karlaeprintingedge.com Posted December 2, 2014 Share Posted December 2, 2014 I'm having issues with using ".exists" when trying to identify if a resource exists. In my code, we want to check to see if a resource exists, and if it does we want to turn on and off certain pages by using a global function called ActivatePage(). Whenever the resource does exist, the code works fine. Whenever the resource does not exist, it gives me an error on the CreateResource line and skips all of the if statements. Please help!! This code is in the OnRecordStart rule: Pic = CreateResource(Field("aao_1") + ".pdf","graphic"); aaotwo = Field("aao_2"); if (aaotwo != "") activatePage(3,4); else if (Pic.exists) activatePage(1,2); else activatePage(3,4); Quote Link to comment Share on other sites More sharing options...
tobarstep Posted December 2, 2014 Share Posted December 2, 2014 The CreateResource() is returning an error since the file you're looking for doesn't exist. You could wrap it in a try/catch block. So, if you're only looking at aao_1 when aao_2 is empty, this worked for me: if (Field("aao_2") == "") { try { CreateResource(Field("aao_1") + ".pdf"); activatePage(1,2); return; } catch (e) { // Do nothing } } activatePage(3,4); Of course in my testing I didn't have your custom function so I was just using FusionPro.Composition.SetBodyPageUsage(), but the principle is the same. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted December 2, 2014 Share Posted December 2, 2014 You should be able to just add the optional nonExistOK parameter to the CreateResource function. If if is set to true it should ignore that error. CreateResource(Field("aao_1") + ".pdf", "graphic", true); 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.