Jump to content

Adding a line break in if/then statement


spartanberry

Recommended Posts

Hello,

I am taking my first shot at pulling data from an external source. The code validates ok but I am having a few problems with it.

 

- The data doesn't preview or show up when composed. I get the name of the rule in the text box and that is it.

- When validating it pulls the same date when the value of "Cty" is 11, 21 or 35.

- I'd like to add more than one line of text. For example, I'd like to have it pull the date then break to the next line and enter the time, break again, the location, ect. I have tried using /n and <br> but both cause syntax errors. Maybe I'm not using them correctly.

 

Help? Please :)

 

x = 1
var ext = new ExternalDataFile("ctyannuals.csv", ",");
var date = ext.GetFieldValue(x, "Date");
var time = ext.GetFieldValue(x, "Time");
var location1 = ext.GetFieldValue(x, "Location 1");
var location2 = ext.GetFieldValue(x, "Location 2");
var location3 = ext.GetFieldValue(x, "Location 3");
{
if (Field("Cty") == "11")
   return date;

else if (Field("Cty") == "21")
   return date;

else if (Field("Cty") == "35")
   return date;

else 
   return Rule("rule_firstname") + ", We want to pay your next Ford payment. See the article on page 3 to find out more.";
   }

Link to comment
Share on other sites

- The data doesn't preview or show up when composed. I get the name of the rule in the text box and that is it.

Usually a preview that shows the rule name indicates an error with the result of the rule. This could be as simple as missing the semi-colon in the first line.

 

- When validating it pulls the same date when the value of "Cty" is 11, 21 or 35.

Is this due to the fact that you are always pulling the same date from the external data file regardless of city (x = 1)?

 

- I'd like to add more than one line of text. For example, I'd like to have it pull the date then break to the next line and enter the time, break again, the location, ect. I have tried using /n and <br> but both cause syntax errors. Maybe I'm not using them correctly.

Using the <br> tag sounds like the right way to go, but I don't see anything in your posted code showing how you are implementing this. Are you remembering to enclose the tag in quotes and return the value as tagged text? Where is the code pulling time and location from (primary data file, date string, etc)?

Link to comment
Share on other sites

Thanks for your help Eric!

 

I figured out the first question today. A rookie mistake :) . I forgot that I changed the name of the rule and left the old name in the text box. Oops. Now it is previewing and composing the data. I do still have the problem with the date. I've seen x=1 on several examples when pulling from external data. What does that refer to? Is it the first line in the external file? The date that keeps pulling is on the first line. I attached the file that I'm using.

 

For the line break; I get an syntax error when using "<br>" in my code. Am I using it right?

 

x = 1
var ext = new ExternalDataFile("ctyannuals.csv", ",");
var date = ext.GetFieldValue(x, "Date");
var time = ext.GetFieldValue(x, "Time");
var location1 = ext.GetFieldValue(x, "Location 1");
var location2 = ext.GetFieldValue(x, "Location 2");
var location3 = ext.GetFieldValue(x, "Location 3");
{
if (Field("Cty") == "11")
   return date "<br>" time "<br>" location1 "<br>" location2 "<br>" location3 "<br>";

else if (Field("Cty") == "21")
   return date;

else if (Field("Cty") == "35")
   return date;

else 
   return Rule("rule_firstname") + ", We want to pay your next Ford payment. See the article on page 3 to find out more.";
   }

ctyannuals.zip

Link to comment
Share on other sites

Assuming you have a Field("compare") in your primary data file for each record which contains the required "Cty" information in your external data file, you can simply add a line in your code to locate the proper record in the external data file that matches the "primary key" in your main data file.

 

For instance, try replacing your "var x=1" line with the following:

var x = ext.FindRecord("Cty", Field("compare"));

Instead of pulling the information from record 1 each time, FP will now see which "Cty" your current record uses in the primary data file and locate the corresponding record from the external data file to gather the correct details.

Link to comment
Share on other sites

Ahhh....I can see where x=1 would throw things off then. I will try that in the AM because I don't have FP on my home pc.

 

I am using the <br> tag in the highlighted area below. I'm probably not doing it correct but can't find an example of the proper usage of the tag.

 

 

x = 1
var ext = new ExternalDataFile("ctyannuals.csv", ",");
var date = ext.GetFieldValue(x, "Date");
var time = ext.GetFieldValue(x, "Time");
var location1 = ext.GetFieldValue(x, "Location 1");
var location2 = ext.GetFieldValue(x, "Location 2");
var location3 = ext.GetFieldValue(x, "Location 3");
{
[color="Blue"]if (Field("Cty") == "11")
   return date "<br>" time "<br>" location1 "<br>" location2 "<br>" location3 "<br>";[/color]

else if (Field("Cty") == "21")
   return date;

else if (Field("Cty") == "35")
   return date;

else 
   return Rule("rule_firstname") + ", We want to pay your next Ford payment. See the article on page 3 to find out more.";
   }

Link to comment
Share on other sites

Ah, another minor oversight. Whenever you are mixing variables with raw text, you need to concatenate them with a plus sign so your blue-highlighted code should read:

if (Field("Cty") == "11") return date + "<br>" + time + "<br>" +  location1 + "<br>" + location2 + "<br>" + location3 + "<br>";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...