danapip.alaska.com Posted January 21, 2009 Share Posted January 21, 2009 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 More sharing options...
jshobar Posted January 21, 2009 Share Posted January 21, 2009 dana- I'd have to jump in more to know for sure, but I suspect that the line "return Charge_Variable" is exiting the loop. Try loading all charges into an array rather than returning a value. Link to comment Share on other sites More sharing options...
danapip.alaska.com Posted January 21, 2009 Author Share Posted January 21, 2009 The sample list I've seen from the customer gives me the impression that there could be many many different types of charges. I'm afraid that maintaining an array could be difficult. I may be in over my head, but I was hoping there might be a tweak needed to my code to keep the loop going. Link to comment Share on other sites More sharing options...
jshobar Posted January 21, 2009 Share Posted January 21, 2009 "return" will exit the loop, so you need to put each match into an array or even a list of variables, for instance, if you know there are at most 5 charges, use charge1, charge2, etc.... Link to comment Share on other sites More sharing options...
Dan Korn Posted January 22, 2009 Share Posted January 22, 2009 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 More sharing options...
danapip.alaska.com Posted January 22, 2009 Author Share Posted January 22, 2009 That worked! Thanks for the help. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.