Copy link to clipboard
Copied
I have the following script in a custom calculation property:
var a = this.getField("5a.0.4");
var b = this.getField("5a.1.4");
var c = this.getField("5a.2.4");
var d = this.getField("5b1");
var y = this.getField("2ea3").value;
var x = Number(a.value)+Number(b.value)+Number(c.value)+Number(d.value);
if(x != 0 && y>=x){
event.value = 0;
a.display = display.hidden;
b.display = display.hidden;
c.display = display.hidden;
d.display=display.hidden}
else{
event.value = x;
a.display = display.visible;
b.display = display.visible;
c.display = display.visible;
d.display=display.visible}
I wish to allow the user to also just type in a manual value, thus overriding the script if desired. Unfortunately, the script overrides the manual entry. Is there a way to switch off the script and allow a manual entry that stays visible?
OK, then you can do it like this:
if (event.source!=null && (event.source.name=="5a.0.4" || event.source.name=="5a.1.4" || event.source.name=="5a.2.4" || event.source.name=="5b1" || event.source.name=="2ea3")) {
// put the rest of the calculation code here
}
Copy link to clipboard
Copied
Yes, but you need to carefully think how it should work.
What should happen if they change the value of, for example, the "5a.0.4" field after they entered a custom value into the calculated field? Should it overwrite their custom value and re-apply the automatic calculation?
Copy link to clipboard
Copied
I would say yes, it would overright the custome value.
Copy link to clipboard
Copied
OK, next question: Are all the five fields used for the automatic calculation all have values inputted by the user, or do some of them have automatic calculations of their own?
Copy link to clipboard
Copied
they are all inputted by user.
Copy link to clipboard
Copied
OK, then you can do it like this:
if (event.source!=null && (event.source.name=="5a.0.4" || event.source.name=="5a.1.4" || event.source.name=="5a.2.4" || event.source.name=="5b1" || event.source.name=="2ea3")) {
// put the rest of the calculation code here
}
Copy link to clipboard
Copied
Would this work if someone had put an input into "2ea3" which is the sum ofthe other fields that was a different number than the sum ofthe other fields? Like if all the other fields added up to 10, could someone override that and put in, for instance, 56, 100 or 10000000, or any other number?
Copy link to clipboard
Copied
Sure, they can just enter the custom value into one of the source fields, and leave the others empty to get the same result. That might be easier...
Copy link to clipboard
Copied
Well, I tried this code:
if (event.source!=null && (event.source.name=="5a.0.4" || event.source.name=="5a.1.4" || event.source.name=="5a.2.4" || event.source.name=="5b1" || event.source.name=="2ea3")) {
var a = this.getField("5a.0.4");
var b = this.getField("5a.1.4");
var c = this.getField("5a.2.4");
var d = this.getField("5b1");
var y = this.getField("2ea3").value;
var x = Number(a.value)+Number(b.value)+Number(c.value)+Number(d.value);
if(x != 0 && y>=x){
event.value = 0;
a.display = display.hidden;
b.display = display.hidden;
c.display = display.hidden;
d.display=display.hidden}
else{
event.value = x;
a.display = display.visible;
b.display = display.visible;
c.display = display.visible;
d.display=display.visible}
I get Sytax Error Missing } in compound statement 21:at line 22
Copy link to clipboard
Copied
Put one more } at the end.
Copy link to clipboard
Copied
It seems I am back to where I started. The point of this code was to make event.value = 0; if
var y = this.getField("2ea3").value
was greater than var x. I need a way to manually override that. However, now, if it is overrriden, it will not go back to that comparative function if the user goes back to any of the contributory fields
[var a = this.getField("5a.0.4");
var b = this.getField("5a.1.4");
var c = this.getField("5a.2.4");
var d = this.getField("5b1");] (square brackets are not in the JS)
and changes them. There is no way to revert so that the comparison is completed again. It terminates the comparison functionality. Is there a way to rever the who thing so that it looks at var y? Or even if the user does not go back to change var a, b, c, or d, is there a way to keep the functionality of the script so that is continues to check to see if var y is greater than the var x?
Again, I really really appreciate all the help here
Copy link to clipboard
Copied
Your desired behavior relies on some complex conditions. As try67 mentioned, you have to think about all the conditions involved and how they will affect the behavior. In fact, these should all be written down in a table. Then you design the code to fit the conditions listed in the table.
According to the code you posted above.
1. When data is entered into any of the input fields the calculation takes place. So all you have to do to break the override is to enter data into any of these fields.
2. When the "2ea3" field value is greater than the sum of the other fields, the other fields are hidden. Therefore, the only field left to change for the override is the "2ea3" field. Enter data into this field and the override will be broken.
If this isn't what you wanted to happen, then again, you need to write down exactly the the conditions that lead to each change in the field value, and the override.
If necesary, you could have a button that resets the whole process.