Jump to content

Need help using the CreateResource() function!


Recommended Posts

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...