Landisa Posted April 17, 2017 Share Posted April 17, 2017 (edited) I have a form with a key file that can have multiple keys. My goal is to add code prevent creating multiple copies of the form based on if the field has the same key as previous. Example: KEY1 KEY2 312456 103489 312456 504723 312456 654871 My form already turns on when it finds the field that matches it: if (Field("Letter_Code") == "010") { FusionPro.Composition.SetBodyPageUsage("Letter_010", true); } I was thinking of using the FieldChanged rule and composeThisRecord rule to help prevent creating multiple letters since they KEY1 is the one we are basing the code from even though we need both keys for different table pulls. My code ended up being like: FusionPro.Composition.composeThisRecord = false; if (FieldChanged(Field(KEY1"))) { FusionPro.Composition.composeThisRecord = true; } OR if (FieldChanged(Field("KEY1"))) { FusionPro.Composition.SetBodyPageUsage("Letter_010", true); } However, when I run this code it turns the whole form unrenderable. Am I using this code incorrectly? Any suggestions? If requested I can mock up a new file for viewing due to the sensitive nature of the form. Edited May 25, 2017 by Landisa Solved Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 17, 2017 Share Posted April 17, 2017 Instead of this: if (FieldChanged(Field("KEY1"))) You want this: if (FieldChanged("KEY1")) Quote Link to comment Share on other sites More sharing options...
Landisa Posted April 17, 2017 Author Share Posted April 17, 2017 Instead of this: if (FieldChanged(Field("KEY1"))) You want this: if (FieldChanged("KEY1")) This did the job! Now is there anyway to get that form to preview using the code? Runs beautiful on the server, just can't preview the form now. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 17, 2017 Share Posted April 17, 2017 This did the job! Now is there anyway to get that form to preview using the code? Runs beautiful on the server, just can't preview the form now. Well, in Preview, it's only actually processing a single record of data, so the "FieldChanged" will always return false, since there's no previously processed record to compare the current record's field value to. This should work, though: if (FieldChanged("KEY1") || IsPreview()) Quote Link to comment Share on other sites More sharing options...
Landisa Posted April 18, 2017 Author Share Posted April 18, 2017 Well, in Preview, it's only actually processing a single record of data, so the "FieldChanged" will always return false, since there's no previously processed record to compare the current record's field value to. This should work, though: if (FieldChanged("KEY1") || IsPreview()) Awesome! This works like a charm! Mostly just need to make sure the fields are populating. If the preview doesn't show the "FieldChanged" correctly but still runs on the server without issues, we are good to go! Thanks again for the help! ^^, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.