Jump to content

ExternalDataFileEx For Loop


Recommended Posts

I am creating a job that references a customer id and sometimes multiple charges associated with that customer id in an external data source. The For Loop used in my code doesn't seem to be working correctly. Fusion Pro will return the first charge associated with the customer id but it stops there rather than looping and looking through the rest of the external data source for any other instances of that costomer id. My code looks something like this:

 

if (FusionPro.inValidation)

Rule("OnJobStart");

 

var test_val = Field("ID");

 

for (var i = 0; i <= Test_File.recordCount; i++)

{

var ID_Variable = Test_File.GetFieldValue(i, "ID");

var Charge_Variable = Test_File.GetFieldValue(i, "Charge");

if (test_val == ID_Variable)

return Charge_Variable;

}

 

Any assistance would be greatly appreciated.

Link to comment
Share on other sites

It's not that difficult to use an array. Try this:

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

var test_val = Field("ID");

var matches = new Array();

for (var i = 0; i <= Test_File.recordCount; i++)
{
 var ID_Variable = Test_File.GetFieldValue(i, "ID");
 var Charge_Variable = Test_File.GetFieldValue(i, "Charge");
 if (test_val == ID_Variable)
   matches.push(Charge_Variable);
}

return matches;

Of course, you haven't specified exactly what you want to do with these multiple values in your job once you've extracted them from the external data file. You can always do something like this to put each one on a separate line in the output:

return matches.join("<br>\n");

Using similar logic, you could put the results in a table or something else too.

 

https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Predefined_Core_Objects/Array_Object

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array

 

P.S. Don't be afraid to click "Go Advanced" and use the # icon to put your code into a [noparse]

[/noparse] block.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...