Jump to content

globally formatting multiple fields?


sschardan

Recommended Posts

I routinely use a javascript to format numbers to add the appropriate commas, but I only know how to do this by creating an individual rule for each variable field. I am working on a job now that contains about 40 fields of monetary values that only contain a dollar sign with the money amount, no commas. Is there any way to globally format all these fields, or should I just have my data department fix the data?

 

Thanks,

 

Scott

 

FP 6.2P1a

Mac 10.6.2

Link to comment
Share on other sites

Do all your fields get used in a single text box? If so, you could convert your formatting code to a function and then set up a loop to cycle through all your monetary fields, passing each through the function and tacking them on to a single output variable that you return in a single rule.

 

If the fields are used in several text frames or multiple times, the function could still be set up as a global rule, but then you'd be calling it 40 separate times. Less typing for you, but still a lot of rules. If this is the case, I would think it would be easier to format the input data before bringing it into FP.

Link to comment
Share on other sites

If this is the case, I would think it would be easier to format the input data before bringing it into FP.

 

E, could you write a rule that would "structure" all columns properly without having to format data? I would be more worried that the data department would possibly structure the columns wrong and with dealing with $, that would be a nightmare.

 

I would imagine the $ amounts aren't always the same in terms of # of digits you are dealing with?

 

ex:

112.00 | 1112.00 | 11112.00 | 111112.00 | etc.........

 

So the output should be:

112.00 | 1,112.00 | 11,112.00 | 111,112.00

 

How would you go about creating a rule that would change all 40 columns to be structured properly?

 

Thanks

Link to comment
Share on other sites

Unfortunately, the fields are spread throughout the file as individual text boxes which would necessitate individual rules. I am proceeding with the fix in our data processing department. I was just hoping that someone could educate me in a crafty way to work around this.

 

Scott

Link to comment
Share on other sites

This is sort of unexplored territory for me, but you might be able to create a FOR loop in an OnRecordStart callback rule to cycle through all the fields with dollar amounts, format them per a single function, and dump them into an associative array using the field's name as the indice. Then when placing the formatted number into your text frame(s), you would call the data by referencing Array[Field("Name")] rather than Field("Name"). Ideally, for this to work, you would want all the field names containing your numbers to be named similarly; perhaps "Value1", "Value2, etc.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...