bkurzbuch Posted September 21, 2017 Share Posted September 21, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 21, 2017 Share Posted September 21, 2017 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; Quote Link to comment Share on other sites More sharing options...
bkurzbuch Posted September 22, 2017 Author Share Posted September 22, 2017 Thank You Dan. Exactly what I needed. Have a great weekend Quote Link to comment Share on other sites More sharing options...
step Posted September 22, 2017 Share Posted September 22, 2017 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"); }).join("\n"); Quote Link to comment Share on other sites More sharing options...
bkurzbuch Posted September 22, 2017 Author Share Posted September 22, 2017 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 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.