sbellia Posted December 13, 2017 Share Posted December 13, 2017 Hi everybody, I'm looking to count the amount of times the Insert picture rule returns a certain value and return it to a log file or on the screen after I compose the template. Whatever is easier. I want to count the amount of times the rule spits out the default value which is the final else return. What do you recommend? var Var1 = "@PHOTO"; var Var2 = ".jpg"; var Var3 = "S:\\Customer Files COPY CENTER\\Prosdigital\\HOLIDAY MAILER 12-11-17\\ARTWORK"; var Var4 = "000000_SA0.jpg"; temp = ''; var_extension = ''; has_extension = ''; if (Var3 == "") Var3 = Var3; else { if (FusionPro.isMac) Var3 = Var3 + ":"; else Var3 = Var3 + "\\"; } for (i=0; i<Field(Var1).length; i++) { temp = Mid(Field(Var1), Field(Var1).length-i,1); var_extension = temp + var_extension; var_extension = ToLower(var_extension); if(var_extension == ".png" || var_extension == ".pdf" || var_extension == ".gif" || var_extension == ".eps" || var_extension == ".tif" || var_extension == ".tiff" || var_extension == ".jpg" || var_extension == ".jpeg") { has_extension = "true"; i=Field(Var1).length; } else has_extension = "false"; } if(has_extension == "true") Pic = CreateResource(Var3 + Field(Var1), "graphic", true); else { if(Var2 == ".jpg") { Pic = CreateResource(Var3 + Field(Var1) + ".jpeg", "graphic", true); if (Pic.exists) Pic = Pic; else Pic = CreateResource(Var3 + Field(Var1) + ".jpg", "graphic", true); } if(Var2 == ".tif") { Pic = CreateResource(Var3 + Field(Var1) + ".tif", "graphic", true); if (Pic.exists) Pic = Pic; else Pic = CreateResource(Var3 + Field(Var1) + ".tiff", "graphic", true); } if(Var2 == ".png" || Var2 == ".pdf" || Var2 == ".eps" || Var2 == ".gif") { Pic = CreateResource(Var3 + Field(Var1) + Var2, "graphic", true); } } if (Pic.exists) { return Pic; } else { return CreateResource(Var3 + Var4, "graphic", true); } Quote Link to comment Share on other sites More sharing options...
merski007 Posted December 13, 2017 Share Posted December 13, 2017 add a counter variable to the globals area and throw an incrementer on it every time the scenario occurs. then create a callback rule of OnRecordEnd or OnJobEnd and add the FP function Print(). So maybe something like this: var counter; //global var counter++; //every time scenario occurs Print(counter); //this will add the text to the .msg file that is created during compose. Quote Link to comment Share on other sites More sharing options...
sbellia Posted December 14, 2017 Author Share Posted December 14, 2017 Thanks merski007, But im pretty noob to this. Can you more specific in the language of the code? Thanks Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted December 14, 2017 Share Posted December 14, 2017 First, from the main Rules dialog, click the JavaScript Globals button, then enter this syntax and click OK; defaultGraphicTimesUsed = 0; Then, in your main rule, directly above the line that has "return CreateResource" in it, add this line: defaultGraphicTimesUsed++; // <- declared in JavaScript Globals So the last few lines of the rule are like so: if (Pic.exists) { return Pic; } else { defaultGraphicTimesUsed++; // <- declared in JavaScript Globals return CreateResource(Var3 + Var4, "graphic", true); } Save that rule. Then from the Rules dialog, click the New button, then click Callback, and select the OnJobEnd callback, and enter this syntax: Print("Default graphic was used " + defaultGraphicTimesUsed + " time(s)."); Save that rule. Then compose and view the log file, and the message should be near the end. Quote Link to comment Share on other sites More sharing options...
sbellia Posted December 14, 2017 Author Share Posted December 14, 2017 THANK YOU! Worked great! 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.