Skip to main content
lawrencer20029198
Known Participant
August 18, 2021
Answered

Can a custom calculation script be overriden?

  • August 18, 2021
  • 1 reply
  • 1626 views

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?

This topic has been closed for replies.
Correct answer try67

they are all inputted by user.


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
}

1 reply

try67
Community Expert
Community Expert
August 18, 2021

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?

lawrencer20029198
Known Participant
August 18, 2021

I would say yes, it would overright the custome value.

try67
Community Expert
Community Expert
August 19, 2021

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?