Script for aligning currency when there are negative numbers ()

Hi - I am trying to apply the below script to align my currency numbers when there is a negative number. For example, I want to align the numbers as such instead of the default alignment. When I try to use the script below, I get an error message " can not call method charAt from undefined". This script works fine outside of Connect.

809,000.00
(150,152.25)

NumberInStringFormatToAlign = record.tables.CurrentQTR[“Contribution”];
var LastCharacterInString = record.tables.CurrentQTR[“Contribution”].charAt(record.tables.CurrentQTR[“Contribution”].length - 1);

if (LastCharacterInString != ")") {
    NumberInStringFormatToAlign = NumberInStringFormatToAlign + " ";
}

Does anyone have any suggestions?

Thank you
Amy

Why is there 2 closing parentheses with a double-quotes in your If statement?

if (LastCharacterInString != ")") {
NumberInStringFormatToAlign = NumberInStringFormatToAlign + " ";
}

I guess you lack the row level in the CurrentQTR table and a field reference is missing. The following refers to the “Contribution” field in the first row of the “CurrentQTR” data table:

var foo = record.tables[“CurrentQTR”][0].fields[“Contribution”];

if ( LastCharacterInString IS NOT ROUNDBRACKET )

hamelj - There aren’t two closing parenthesis. it is “)” and then the closing parenthesis.

Hi Erik - added the above line of code and still getting same error message.

Guess the field type of “Contribution” is Currency, in that case you would need to cast the value to a string first. Consider the following (notice the toString();):

var NumberInStringFormatToAlign = record.tables["CurrentQTR"][0].fields["Contribution"].toString();

In data mapper, it is a string ( ex. -809,000.00). I format it as currency no symbol so that it shows as (809,000.00).

I added your suggestion above and still getting the same error ( cannot call method “charAt” of undefined. I also changed the script a little bit. I now have the below script. The error message goes away but there are no results.

NumberInStringFormatToAlign = record.tables[“CurrentQTR”][0].fields[“Contribution”].toString();
LastCharacterInString = NumberInStringFormatToAlign.charAt(NumberInStringFormatToAlign.length - 1);

if (LastCharacterInString != ")") {
    NumberInStringFormatToAlign = NumberInStringFormatToAlign + " ";
}