Jump to content

Help with populating fields from XDF


jhaughey

Recommended Posts

Been banging my head against the wall for two days on this, would appreciate any help.

 

In the UI form for a variable product hosted on Marcom central, there is a dropdown with a list of store locations. I would like for the specific address fields (street, city, etc.) to be looked up from an XDF, and fill in the text boxes in the form when the user chooses the location.

I've tried this 10 different ways and can not get it to work. What is the right way to do this?

Thanks!

Link to comment
Share on other sites

I feel your pain, I worked all day yesterday to get this worked out.

 

There are two basic scripts you need, plus the XDF file.

 

These examples work by selecting a City from a pulldown in Marcom and returning the address and a graphic of the state.

 

XDF File

Your XDF data should be a Tab Delimited txt file. It needs to be loaded in Marcom. When you go to configure the template in Marcom, there is a tab at the top for "Shared External Data Files" go there, click on "Upload New Data File". (If you don't have the OnJobStart script with the call to the data file in your FusionPro Template, Marcom won't acknowledge the fact that the template requires an XDF file.)

 

You need to map the data by selecting your Marcom Product from the list, click "Map Products". From the list select your Product and click save. (There is a note I read that says you need to have Published the template, for it to show up when you map the data.)

 

In Marcom, when configuring the template, under the "Proof/Press Settings" tab, go down to "Edit External Data File Settings" and make sure the correct data file is selected. When you are finished publish normally in Marcom.

 

The Scripts

The scripts below require the values you have in your pulldown in Marcom, to be the first column record in your XDF file. This allows us to compare and select the right record.

 

In Fusion Pro

The first script is a OnJobStart script that calls your data. The file name MUST match the file name! The "\t" in the script tells us it is a Tab Delimited file.

//OnJobStart script. Calls the data file and loads it into the job. This can reside on an external server. Allows you to update it without having to update anything in Marcom.

//this rule goes into OnJobStart
// Calling the XDF File for this template

XDF = new ExternalDataFileEx("My-First-XDF-data.txt","\t"); // List your XDF file here

return XDF.valid;

The next script you need is for the data call. Treat this like any other rule in Marcom. One script (rule) per Field, unless you are doing some formatting in your script. (which this one does, if you don't want to do formatting just remove the other variables and return only one.)

// Assigning text values from a text pulldown selection.

if (FusionPro.inValidation)
   Rule("OnJobStart"); // This calls the database we set up in the Callback script

Address = ""; // This declares the variables we will place in our template with this script, add or remove as necessary.
City = "";
State = "";
Zip = "";

for (i = 1; i < XDF.recordCount+1; i++) // We step through the database looking at each record

{
   PropName = XDF.GetFieldValue(i, 0); // This looks at the very first record in our database so we can compare it to the value selected in the pulldown menu in the Marcom Template.
       {
           if (Field("PulldownInMarcomTemplate") == PropName) // The Field is our FusionPro Document Pulldown, we compare the pulldown to the first field in our data
               {    
                   var Address = XDF.GetFieldValue(i, 1); // Assign the data to a variable. i = is the record from our counter
                   var City = XDF.GetFieldValue(i, 2); // The number is the column in the database. Javascript starts counting columns at 0
                   var State = XDF.GetFieldValue(i, 3);
                   var Zip = XDF.GetFieldValue(i, 4);
               }
       }
}

return Address + "<br>" + City + ", " + State + " " + Zip; // This is what is returned to the field in our template. This has formatting, so multiple variables appear in one Field.

// End

If you want to assign a graphic based on the same Marcom pulldown, you can use this script.

// Assigning a graphic from a text match.

if (FusionPro.inValidation)
   Rule("OnJobStart");

var Pic = NullResource();  // this should be a blank/null resource as a default

for (i = 1; i < XDF.recordCount+1; i++)
   {
       PropName = XDF.GetFieldValue(i, 0);
           {
               if (Field("PulldownInMarcomTemplate") == PropName) // Compare the value of Field "PulldownInMarcomTemplate" with data
                   {
                       var Image = XDF.GetFieldValue(i, 7);  // XDF contains image names
                   }
           }
   }

if (Image != "")
   {
       var Pic = new FusionProResource(Image, "graphic", "true");
   }

return Pic;

I hope this helps. You can do more, but this is as far as I have gotten so far. Others may have a better approach.

 

Good Luck.

Link to comment
Share on other sites

×
×
  • Create New...