Copy link to clipboard
Copied
I have the following fields in my document:
Total Revenue - this is manually entered field
Gross Profit - this has a calulation in it
Actual Gross Profit %
Originally I had the calculation in Acutal Gross Profit % as Gross Profit/Total Revenue and I was getting message "the value entered does not match the format of the field". From searching around online I know that this happens when Total Revenue field is blank and a formula can't be used when divisible by zero. I've tried different scripts suggested but I'm having a hard time having it work with my specific scenario. Can anyone help? Java script is way beyond my knowlege base so if someone can provide a script for me that I cna use that would be helpful.
I was able to get rid of the message with the following code, but now calculation doesn't work.
var numerator = +getField("Gross_Profit").value;
var denominator = +getField("Total_Revenue").value;
if (denominator !== 0) {
event.value = numerator / denominator;
} else {
event.value = "";
}
Copy link to clipboard
Copied
That message that you were getting is due to textfield objects formatted different from each other.
For example, if you had calculations in another field with a field formatted as a percentage number, that field will expect the text string value to be the same.
Before you experiment with a JavaScript script, you should check that the fields with dependent calculations have the same formatting that
it expects.
The script that you say resolved the issue has nothing to do with anything that doesn't work.
The script works, the issue is if you expect a result to be displayed as 25% or 0.25?
Copy link to clipboard
Copied
Yes, I require the result to be a %
Copy link to clipboard
Copied
Check the Javascript console for errors.
Copy link to clipboard
Copied
Well, in my case I decided to not use the script, instead I decided to use Simplified field notation in the "Actual_Gross_Profit" field.
The simplified field notation in my example is :
Gross_Profit / Total_Revenue
And both of those textfields has no formatting.
In the Format tab, however, I selected Percentage from the dropdown menu with 0 decimal places.
This will display the result of that divisio. with a string value of 25% if, for example, the user inputs 25 in the Gross_Profit field and 100 in the "Total_Revenue" field.
If, on the other hand, you still want to use the script, this is how I would do it as a custom calculation script instead of a simplified field notation:
var numerator = +getField("Gross_Profit").value;
var denominator = +getField("Total_Revenue").value;
if (denominator !== 0) {
event.value = util.printf("%d", Math.ceil((numerator /100) / (denominator/100)*100))+"%";
} else {
event.value = "";
}
There are many ways of achieving this with JavaScript, so in my case this is what delivered the results that I was looking for based on your inquiry.
Copy link to clipboard
Copied
Thank you, I appreciate your time and assistance. It's just not working for me. Like I said, over my head so tough for me to figure out. Seems like such a simple equation. Obviously more to it.
Copy link to clipboard
Copied
You're welcome, and sorry if my guidance just didn't work for you.
Copy link to clipboard
Copied
Can you share the form?