Expand my Community achievements bar.

SOLVED

locale addinstance

Avatar

Level 2

Hello All,

I am fairly new to Livecycle (designer now) and am having a small issue with a table on my form. I have created 4 radio buttons which correspond to 4 different currencies.

I have the table below this in a different subform which contains on one row qty, unit cost and sub total fields. Through the magic of java on the radio button change script I have managed to have the GST and Grant total subforms disappear when another currency is selected and the  locale of these currency fields change depending on currency, so the formatting of the prices changes for Euro or AUD etc.

The problem occurs when I add a new row to the table using add instance buttons, it defaults back to AUD. The top line is correct but all subsequently added rows are back to AUD settings. Is there a way I can add into the script for it to change the locale for all subsequent instances?

Here is the code I added to the change script of the radio buttons.

form1.MainPage.UserInformationTable.Table1.Row8.Currency.CurrencyRB::change - (JavaScript, client)

if (this.rawValue == "AUD")

{

form1.MainPage.GST.presence= "visible";

form1.MainPage.TotalincGST.presence= "visible";

form1.MainPage.Itemtable.ItemTable.Row1.SubtotalCalc.locale= "en_AU";

form1.MainPage.Itemtable.ItemTable.Row1.UnitcostTxt.locale= "en_AU";

form1.MainPage.Itemtable.ItemTable.Grandtotal.Grandtotal.locale= "en_AU";

}

else if (this.rawValue == "EUR")

{

form1.MainPage.GST.presence= "hidden";

form1.MainPage.TotalincGST.presence= "hidden";

form1.MainPage.Itemtable.ItemTable.Row1.SubtotalCalc.locale= "fr_FR";

form1.MainPage.Itemtable.ItemTable.Row1.UnitcostTxt.locale= "fr_FR";

form1.MainPage.Itemtable.ItemTable.Grandtotal.Grandtotal.locale= "fr_FR";

}

else if (this.rawValue == "USD")

{

form1.MainPage.GST.presence= "hidden";

form1.MainPage.TotalincGST.presence= "hidden";

form1.MainPage.Itemtable.ItemTable.Row1.SubtotalCalc.locale= "en_US";

form1.MainPage.Itemtable.ItemTable.Row1.UnitcostTxt.locale= "en_US";

form1.MainPage.Itemtable.ItemTable.Grandtotal.Grandtotal.locale= "en_US";

}

else if (this.rawValue == "CHF")

{

form1.MainPage.GST.presence= "hidden";

form1.MainPage.TotalincGST.presence= "hidden";

form1.MainPage.Itemtable.ItemTable.Row1.SubtotalCalc.locale= "de_CH";

form1.MainPage.Itemtable.ItemTable.Row1.UnitcostTxt.locale= "de_CH";

form1.MainPage.Itemtable.ItemTable.Grandtotal.Grandtotal.locale= "de_CH";

}

As I said i am new to this and am sure there is a more elegant way of doing this, I have tried removing the three object references and simply changing the local of the table or the subform but this doesn't seem to work.

Any assistance on this would be much appreciated!!

Best Regards

Paul

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Paul,

Try moving your code to the calculate event of the Row1 object, so it would look something along the lines of;

if (CurrencyRB.rawValue == "AUD") {

SubtotalCalc.locale= "en_AU";

} else if (CurrencyRB.rawValue == "EUR") {

SubtotalCalc.locale= "fr_FR";

} else if (CurrencyRB.rawValue == "USD") {

SubtotalCalc.locale= "en_US";

} else if (CurrencyRB.rawValue == "CHF") {

SubtotalCalc.locale= "de_CH";

}

You will probably need to fix up the reference to CurrencyRB which might be different in your forms structure.

The calculate event of Row1 is fired whenever a new row is added and because we have added a dependency to CurrencyRB, whenever that field changes, so if they go back and change the currency once they have added some rows they will all change.  Is that what you want or do you allow a mix?

Regards

Bruce

View solution in original post

9 Replies

Avatar

Correct answer by
Level 10

Hi Paul,

Try moving your code to the calculate event of the Row1 object, so it would look something along the lines of;

if (CurrencyRB.rawValue == "AUD") {

SubtotalCalc.locale= "en_AU";

} else if (CurrencyRB.rawValue == "EUR") {

SubtotalCalc.locale= "fr_FR";

} else if (CurrencyRB.rawValue == "USD") {

SubtotalCalc.locale= "en_US";

} else if (CurrencyRB.rawValue == "CHF") {

SubtotalCalc.locale= "de_CH";

}

You will probably need to fix up the reference to CurrencyRB which might be different in your forms structure.

The calculate event of Row1 is fired whenever a new row is added and because we have added a dependency to CurrencyRB, whenever that field changes, so if they go back and change the currency once they have added some rows they will all change.  Is that what you want or do you allow a mix?

Regards

Bruce

Avatar

Level 2

Thanks very much Bruce. I will try that when I’m back at work tomorrow and see if it behaves! Will let you know how I get on

Br

P

Avatar

Level 2

HI Bruce,

i tried this this morning and no effect. This time the locale doesn't seem to change at all. I tried triggering all the changes, and when that didn't work I just tried the subtotalcalc field on it's own, still no effect.

Should I be placing the script into the calculation of each object or the row?

Thanks again

P

Avatar

Level 10

Hi Paul,

One of the hassles about using the calculate event is that you don't always get the exceptions displayed, so in your case I suspect there maybe a exception thrown and silently failing.  Try wrapping the code in a try/catch block and seeing if that gives you any clues.

try {

if (CurrencyRB.rawValue == "AUD") {

  SubtotalCalc.locale = "en_AU";

} else if (CurrencyRB.rawValue == "EUR") {

  SubtotalCalc.locale= "fr_FR";

} else if (CurrencyRB.rawValue == "USD") {

  SubtotalCalc.locale= "en_US";

} else if (CurrencyRB.rawValue == "CHF") {

  SubtotalCalc.locale= "de_CH";

}

} catch (e) {

app.alert(e.toSource())

}

I would add the code to the row object, in my test I only setup the first field from your code, you will need to add the updates to the other fields under the appropriate if statement.  You could add code to each individual field but you have to balance between having the code were the target fields are and having code scattered all over your form.

Bruce

Avatar

Level 2

Hi Bruce,

now I get a Javascript error when I preview:1745039_pastedImage_0.png

Not sure what I did wrong here. Here is the code I ended up with in the calculate script for Row1

form1.MainPage.Itemtable.ItemTable.Row1::calculate - (JavaScript, client)

try {

if (form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB.rawValue == "AUD") {

  SubtotalCalc.locale = "en_AU";

} else if (form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB.rawValue == "EUR") {

  SubtotalCalc.locale= "fr_FR";

} else if (form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB.rawValue == "USD") {

  SubtotalCalc.locale= "en_US";

} else if (form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB.rawValue == "CHF") {

  SubtotalCalc.locale= "de_CH";

}

} catch (e) {

app.alert(e.toSource())

}

Avatar

Level 10

This is saying there's an error on line 4, but blank lines at the beginning aren't counted form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB looks the most likely problem.  Maybe replace the script with an app.alert(form1.MainPage.UserinformationTable.Table1.Row8.Currency.CurrencyRB.rawValue) to see if it is resolving correctly.

You can add references to objects in your script by having the script editor in focus, then hold the ctrl key down and click the object on the design view.  It will probably add something to reference the actual radiobutton but remove that pick up the value from the group, the CurrencyRB object.

Avatar

Level 2

I used the reference ctrl trick there to correct the CurrencyRB link, it is different than what I had so that's progress, but the initial issue still remains, and now for some reason it is throwing up an error about one of the other non critical fields on the row whcih is for a part number.

Weird, I haven't changed anything to do with it. It isn't bringing up a syntx error any more though. 

1745054_pastedImage_0.png

Avatar

Level 10

Hi Paul,

That looks like a standard validation message, is that field set as required?

If you are able to upload your form somewhere, like google docs, dropbox, etc and add a link to it in this thread I can have a look.

Bruce

Avatar

Level 2

Hi Bruce,

I wanted to thank you for your valuable help and believe me I will be using that ctrl design reference trick way more often from now on!!.

This is now working using your calculation script in row 1. It was my reference to currencyRB as you quite rightly suggested, it is now working perfectly.

Many thanks again!!

Br

Paul