Skip to main content
Participant
February 28, 2024
Answered

Help with Javascript!

  • February 28, 2024
  • 2 replies
  • 2181 views

I am trying to run a JavaScript code for the below;

 

I have 3x fields. Field 1 = C    Field 2 = CMin   Field 3 = COK

 

of the value in C is greater than CMin, I need field COK to have the word 'Yes' in green font. If the value in C is less than CMin, I need the field COK to have the word 'No' in red font. 

any help would be much appreciated 

 

[moderator edited the subject for clarity, was "Help"]

 

This topic has been closed for replies.
Correct answer Nesa Nurani

Try this as custom calculation script of "COK" field:

var c = this.getField("C").value;
var cm = this.getField("CMin").value;

if (c === "" || cm === "") {
  event.value = "";} 
else {
  var cNum = Number(c);
  var cmNum = Number(cm);
  event.value = cNum >= cmNum ? "Yes" : "No";
  event.target.textColor = cNum >= cmNum ? color.green : color.red;}

2 replies

Participant
February 28, 2024

Hi. Thank you for your fast response. If they are the same then the word 'yes' in green font is required. Thank you I never thought of that aspect. Really appreciate it

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 29, 2024

Try this as custom calculation script of "COK" field:

var c = this.getField("C").value;
var cm = this.getField("CMin").value;

if (c === "" || cm === "") {
  event.value = "";} 
else {
  var cNum = Number(c);
  var cmNum = Number(cm);
  event.value = cNum >= cmNum ? "Yes" : "No";
  event.target.textColor = cNum >= cmNum ? color.green : color.red;}
Participant
February 29, 2024

Good morning Nesa,

 

firstly thank you for replying. I used the code and it works once, but now fails to reload depending on any changes made. I copy and pasted the code in. Is there something I am missing to refresh each time?

 

thank you for your support

try67
Community Expert
Community Expert
February 28, 2024

What about if they are the same?