Jump to content

Using external data file to pull in image


dml1280

Recommended Posts

I have been using this rule to pull address information into a text box based on the Facility field. It works great.

 

returnStr = '';

if(FusionPro.Composition.isPreview == true || FusionPro.inValidation == true)
{
   Rule("OnJobStart");
}

numRecsExtDF = externalDF.recordCount;

for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++)
{
   if (TaggedTextFromRaw(externalDF.GetFieldValue(recordWalker, 'Facility')) == TaggedDataField("Facility"))
   {
       returnStr += externalDF.GetFieldValue(recordWalker, 'City') + ", ";
       returnStr += externalDF.GetFieldValue(recordWalker, 'State') + " ";
       returnStr += externalDF.GetFieldValue(recordWalker, 'Zip');
   }
}

return returnStr;

 

With this code, when a new location is brought on, I am able to just add a new facility to the library drop down in MarcomCentral and add a line in my external database file and now all products that use this code will automatically have the new location added without having to update individual products.

 

I want to add a field for the facility logos but I can't figure out how to have it called back.

 

Can a graphic be called in using an external database file? I have all of the logos saved in libraries to use across multiple products.

 

Any insight would be appreciated.

 

Thank you.

Link to comment
Share on other sites

Sure, assuming the XDF has the file name, you can do something like this, in a Graphic rule:

var externalDF = new ExternalDataFileEx("yourfilename.txt");

var r = externalDF.FindRecord("Facility", Field("Facility"));
if (r < 1)
   throw "No XDF record for Facility " + Field("Facility");

return CreateResource(externalDF.GetFieldValue(r, "Logo"));

You may need to add the path to the graphics in the job's Search Path, on the Advanced tab of the Composition Options.

Link to comment
Share on other sites

  • 2 weeks later...

Follow up question...this works great for almost all entries.

 

It doesn't work if my facility name has an apostrophe or an ampersand in it. Is there a way to be able to include the apostrophe or an ampersand in the facility name?

 

Sometimes I will need to use the facility name as a field that will be filled in as well.

 

Thank you

Edited by dml1280
Link to comment
Share on other sites

Thank you. It works perfectly.

Great!

I am using the URL for our store image library in MarcomCentral as the search path. Is there any issue that you can for-see with that?

Well, if you're composing the job online in the MarcomCentral DM app, then you shouldn't need to do anything special; the graphics will be automatically found in the image libraries.

 

If you want to see the graphics in an offline composition (like in Acrobat), then you'll have to append the URL base, like so:

var BaseURL = "https://server/foldername/"; // <- your URL here
return CreateResource(BaseURL + externalDF.GetFieldValue(r, "Logo"));

It doesn't work if my facility name has an apostrophe or an ampersand in it. Is there a way to be able to include the apostrophe or an ampersand in the facility name?

Yes, though it depends on how the input data file is encoded. If you're a MarcomCentral DM user, it's probably a tagged markup file, in which case you'll need to change the FindRecord call slightly, like so:

var r = externalDF.FindRecord("Facility", UntaggedDataField("Facility"));

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...