dhealy72 Posted October 14, 2015 Share Posted October 14, 2015 I have an external data file where I'm wanting to pull in Names and Addresses based on a User ID Field. There is a field in the external data file called "UserID", which contains a 6-digit number. What I am trying to figure out is how to write the code so that based off of the number that is entered into the User ID field, the Name, Address and City fields that correspond to that row will be returned. This is what I have so far, which I know is not correct. if (FusionPro.inValidation) Rule("OnJobStart"); var FirstName = ""; var LastName = ""; var Address1 = ""; var Address2 = ""; var City = ""; var PA1 = ""; i = XDF_Address.FindRecord("Value", Field("UserID")) { FirstName = XDF_Address.GetFieldValue(i, "MultiFirstName"); LastName = XDF_Address.GetFieldValue(i, "MultiLastName"); Address1 = XDF_Address.GetFieldValue(i, "MultiAddr1"); Address2 = XDF_Address.GetFieldValue(i, "MultiAddr2"); City = XDF_Address.GetFieldValue(i, "MultiCity"); } var PA1 = ""; PA1 = AppendText(PA2, " ", FirstName); PA1 = AppendText(PA2, "<p>", LastName); PA1 = AppendText(PA2, "<p>", Address1); PA1 = AppendText(PA2, "<p>", Address2); PA1 = AppendText(PA2, "<p>", City); return PA1; Quote Link to comment Share on other sites More sharing options...
step Posted October 15, 2015 Share Posted October 15, 2015 Well it's really hard to say without seeing your data, your external data, or your template. If you would upload them you'd probably get better results out of this forum rather than saying "why doesn't this code work?" and leaving us to guess. But generally speaking, this part looks like it should be working: i = XDF_Address.FindRecord("Value", Field("UserID")); FirstName = XDF_Address.GetFieldValue(i, "MultiFirstName"); LastName = XDF_Address.GetFieldValue(i, "MultiLastName"); Address1 = XDF_Address.GetFieldValue(i, "MultiAddr1"); Address2 = XDF_Address.GetFieldValue(i, "MultiAddr2"); City = XDF_Address.GetFieldValue(i, "MultiCity"); But, again, I'm assuming that you've defined your external data file as 'XDF_Address' and the field that matches up with your 'UserID' field is called "Value." If you return the 'FirstName' variable, do you get the correct result? Anyway, there are some other issues (highlighted in red): if (FusionPro.inValidation) Rule("OnJobStart"); var FirstName = ""; var LastName = ""; var Address1 = ""; var Address2 = ""; var City = ""; [color="Red"]var PA1 = "";[/color] i = XDF_Address.FindRecord("Value", Field("UserID")) [color="red"]{[/color] FirstName = XDF_Address.GetFieldValue(i, "MultiFirstName"); LastName = XDF_Address.GetFieldValue(i, "MultiLastName"); Address1 = XDF_Address.GetFieldValue(i, "MultiAddr1"); Address2 = XDF_Address.GetFieldValue(i, "MultiAddr2"); City = XDF_Address.GetFieldValue(i, "MultiCity"); [color="red"]}[/color] [color="red"]var PA1 = "";[/color] [color="red"]PA1 = [/color]AppendText(PA2, " ", FirstName); [color="red"]PA1 = [/color]AppendText(PA2, "<p>", LastName); [color="red"]PA1 = [/color]AppendText(PA2, "<p>", Address1); [color="red"]PA1 = [/color]AppendText(PA2, "<p>", Address2); [color="red"]PA1 = [/color]AppendText(PA2, "<p>", City); return PA1; Firstly, you don't need those brackets – they aren't doing anything. Secondly, notice that you've defined 'PA1' a total of seven times. What does the 'AppendText' function do? And where is 'PA2' defined? If 'PA2' is a paragraph defined elsewhere, you might be able to change that to the code below to get better results: var PA1 = [FirstName,LastName,Address1,Address2,City].join('<p>'); return PA2 + ' ' + PA1; So all together, you could rewrite the rule to be: if (FusionPro.inValidation) Rule("OnJobStart"); var i = XDF_Address.FindRecord("Value", Field("UserID")); var FirstName = XDF_Address.GetFieldValue(i, "MultiFirstName"); var LastName = XDF_Address.GetFieldValue(i, "MultiLastName"); var Address1 = XDF_Address.GetFieldValue(i, "MultiAddr1"); var Address2 = XDF_Address.GetFieldValue(i, "MultiAddr2"); var City = XDF_Address.GetFieldValue(i, "MultiCity"); var PA1 = [FirstName,LastName,Address1,Address2,City].join('<p>'); return PA2 + ' ' + PA1; 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.