Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Calculating two fields

Avatar

Former Community Member

i want to simply divide one field by another using formcalc or java and have the results in a % in another field. I want to divide PaymentTotal by the MonthlyTotal fields and have the result reflected in a % in the DTI field.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Anytime you are dividing by a object's value it is worth checking it is not null or 0.

if (MonthlyTotal.rawValue != null || MonthlyTotal.rawValue != 0)

{

     this.rawValue = PaymentTotal.rawValue / MonthlyTotal.rawValue;

}

else

{

     this.rawValue = null;

}

  
Also I have set a % pattern in the Object/Field tab.
There was an error in the MonthlyTotal; missing the closing )
In relation to your other post, I see that you imported the form from another application (evident from the name of the root = topmostSubform). This imported the page as a graphic, so the white surround of the page is blocking the grid pattern. This explains why you cannot see the grid. However I would still turn it on and make it as fine as you need it.
Hope that helps,
Niall
PS Also you have mainly used textfields. As you want numbers I would recommend changing these to numericFields. You can do this by selecting them in groups and going to the object type dropdown in the Object/Field tab. This will prevent the users inputting text and fouling up calculations. Lastly you can then set up patterns for these fields (currency to two decimal places).

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

Anytime you are dividing by a object's value it is worth checking it is not null or 0.

if (MonthlyTotal.rawValue != null || MonthlyTotal.rawValue != 0)

{

     this.rawValue = PaymentTotal.rawValue / MonthlyTotal.rawValue;

}

else

{

     this.rawValue = null;

}

  
Also I have set a % pattern in the Object/Field tab.
There was an error in the MonthlyTotal; missing the closing )
In relation to your other post, I see that you imported the form from another application (evident from the name of the root = topmostSubform). This imported the page as a graphic, so the white surround of the page is blocking the grid pattern. This explains why you cannot see the grid. However I would still turn it on and make it as fine as you need it.
Hope that helps,
Niall
PS Also you have mainly used textfields. As you want numbers I would recommend changing these to numericFields. You can do this by selecting them in groups and going to the object type dropdown in the Object/Field tab. This will prevent the users inputting text and fouling up calculations. Lastly you can then set up patterns for these fields (currency to two decimal places).

Avatar

Former Community Member

That is very helpfull thanks. One question....

How do you see the white area? in another application or in code somehow? i want to be able to recognize it in the future.

Avatar

Level 10

Hi,

When you start a new form in LC Designer the top node is "form1" (you can change this to a different name if you want). You are starting off with a blank canvas and you can see the grid.

When you import an existing document, the hierarchy will start off with "topmostSubform".  The name isn't important, it just indicates that the form may have been imported.

In your current form there is a white background over the whole page that cannot be selected and cannot be deleted. This is not a huge problem in itself. It just means that you cannot see the grid.

When I select the page content area I can see that there is no fill, yet there is a background because the grid is not visible.

18-11-2009 21-29-48.png

I think that in most cases it is nearly better to create a form in LC rather than importing (personal view). Depending on how you import an existing document you may end of with less functionality. Check out the help file for further info.

Good luck,

Niall