The CreatorCon Call for Content is officially open! Get started here.

script issue

Cherly
Tera Contributor
I create the script below but is not working correctly. i need it that when a task is closed to require the variable to be  field out. this is a number input. when a number is entered the field still act like is blank and unable to closed the task.
function onSubmit() {
 
var newValue = g_form.getValue('state');
 
if(newValue == 3 || newValue == 4 || newValue == 7) {
if((g_form.getValue('variables.number_of_changes_requested1') ==""));{
g_form.addErrorMessage('Enter Number of Changes Requested.');
return false;
}
}
}
2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

I think i know the problem, but still ill add some debugging steps

AnuragTripathi_0-1695243409233.png

you dont need a ; here

 

Debugging steps:

On a Closed RITM

Hit ctrl+shift+alt+J , it will open javascript debugger

 

Then paste the below and see what alerts you get

 

var stateVal= g_form.getValue('state');

alert(stateVal);
alert((g_form.getValue('variables.number_of_changes_requested1'));

if(stateVal== 3 || stateVal== 4 || stateVal== 7) {
alert('1');
if((g_form.getValue('variables.number_of_changes_requested1') =="")){
alert('2');
g_form.addErrorMessage('Enter Number of Changes Requested.');
return false;
}
}

 

 

-Anurag

Vijay Balotia1
Tera Guru

Hi @Cherly ,

You can make this field mandatory, which by OOTB not allow user to submit the request and throw and error.

var newValue = g_form.getValue('state');
 
if(newValue == 3 || newValue == 4 || newValue == 7) {
g_form.setMandatory('variables.number_of_changes_requested1', true);
}
 
Also seems there is error in your code in if block you are closing the block.
 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks
Vijay Balotia