Jump to content

Pulling data from XDF


Recommended Posts

I have a job that needs a quick turn around for are customer and my javascript skills are not up to the task. I need to pull 2 fields from a XDF. I have the main mailing data source linked to FusionPro and a XDF linked on job start up. The mailing file has a field "CUSTOMER ID"and the XDF has a field "CID". What needs to happen is search through the XDF file and find the just first 10 matches to the "CUSTOMER ID"and return the field "CUSTOMER NAME" & "MASTER CUSTOMER ID"from the XDF. Looking through the XDF there can be as many as 50 records returned, but for right now the customer wants just the first 10. Searching through the forum I can find a few similar jobs, but nothing I can alter myself to get this to work. The data return will be just customer name space and then master id. any help is greatly appreciated. Thanks You
Link to comment
Share on other sites

I'm doing this blind without the data files, but I think you want something like this:

var result = "";
var XDF = new ExternalDataFileEx("your file name");
var recs = XDF.FindRecords("CID", Field("CUSTOMER ID"));
var maxResults = 10; // <- change as needed
for (var i = 0; i < recs.length && i < maxResults; i++)
   result += XDF.GetFieldValue(recs[i], "CUSTOMER NAME") + " " +
                   XDF.GetFieldValue(recs[i], "MASTER CUSTOMER ID") + "\n";
return result;

Link to comment
Share on other sites

Since 'FindRecords' returns an array of record numbers, you could also splice the first 10 and map them to the correct fields like this:

var XDF = new ExternalDataFileEx("your file name");
return XDF.FindRecords("CID", Field("CUSTOMER ID")).splice(0,10).map(function(rec) {
   function ExField(field) { return XDF.GetFieldValue(rec, field) };
   return ExField("CUSTOMER NAME") + " " + ExField("MASTER CUSTOMER ID");

Link to comment
Share on other sites

Very Nice Ste. If I wanted to replace the space in-between "Customer Name" and Master Customer ID" with a tab. How would i do that. i tried replacing the space with <t> tag but did not the results I expected. Do I also need to enter the tab amount or can i control that through the text editor where the rule is applied. Thanks Again
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.

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