Skip to main content
Inspiring
July 10, 2020
Answered

Custom calculation script not working, please help!

  • July 10, 2020
  • 3 replies
  • 1202 views

I don't know why this isn't working. 

I entered the following in custom calculation script in the RegHrs1 text field, but I'm not getting the alert when the Shift Premium checkbox is ticked.  What am I doing wrong??

 

var a = this.getField("ShiftPrem1").value;
var b = this.getField("RegHrs1").valueAsString;


if(a=="Off") event.value=b;
else if (a=="Yes") event.value="";
if ( (b!=="") && (a=="Yes") ) app.alert("Please enter hours first",0);

This topic has been closed for replies.
Correct answer jctremblay

This should be enough...

 

var a = this.getField("ShiftPrem1").value;
var b = event.value;
if ( (b=="") && (a=="Yes") ) app.alert("Please enter hours first",0);
this.getField("RegHrs1").setFocus(); 

 


I have added the focus back to the field.

@try67 is there a way to set back focus to self without having to use this.getField (" ") ?

3 replies

jctremblay
Community Expert
jctremblayCommunity ExpertCorrect answer
Community Expert
July 10, 2020

This should be enough...

 

var a = this.getField("ShiftPrem1").value;
var b = event.value;
if ( (b=="") && (a=="Yes") ) app.alert("Please enter hours first",0);
this.getField("RegHrs1").setFocus(); 

 


I have added the focus back to the field.

@try67 is there a way to set back focus to self without having to use this.getField (" ") ?

Inspiring
July 10, 2020

Fantastic!!  That's works!!  Thank you so much!!  

jctremblay
Community Expert
Community Expert
July 10, 2020

The last line is probably not needed.

 

try67
Community Expert
Community Expert
July 10, 2020

You're accessing the field's previous value. Change this line:

var b = this.getField("RegHrs1").valueAsString;

To:

var b = event.value;

Inspiring
July 10, 2020

I entered the following Custom Calculation script in the RegHrs1 text field, but it still only shows the alert when text is filled in RegHrs, not if the user checks the box if the text field is blank.  What am I missing?

var a = this.getField("ShiftPrem1").value;
var b = event.value;


if(a=="Off") event.value=b;
else if (a=="Yes") event.value="";
if ( (b!=="") && (a=="Yes") ) app.alert("Please enter hours first",0);

Inspiring
July 10, 2020

I hope that makes sense, I only want the alert to show if the user checks the Shift Prem checkbox without entering hours in the RegHrs text field, but it only pops up when hours have been entered.

Inspiring
July 10, 2020

Okay, it works when I enter hours in the text field and then click on the checkbox, but that's the opposite of what I need.  I need the alert if there are no hours entered in RegHrs1 text field when the user checks the Shift Premium box.  Please help me, I don't know what to do 🙂