onSubmit Client Script to make the Add'l comments mandatory based on an Assignment Group change?...

cdavis22
Tera Contributor

Hi All,

 

I've searched this forum a lot & was not able to find an additional solution. I am hoping that someone can help me with a code for an onSubmit client script. 

 

Originally my task to make the additional comments mandatory based on a change to the assignment group was working but some users were able to bypass the client script if they changed the State field. So I figured an onSubmit client script would be better but I am having trouble with the code. 

 

Original code to previous task below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type appropriate comment here, and begin script below

if ((newValue != oldValue) && (oldValue != ' '))

{

g_form.setMandatory('comments', true);
g_form.addInfoMessage('Additional comments are required prior to changing the Assignment group.');

}
}

 

Is it a way I can make this to an onSubmit version?

14 REPLIES 14

@cdavis22 

 

The script mentioned by you is wrong as you are using oldValue & newValue in onSubmit client script, which is not available OOB as you can see in below screenshot:

 

PrinceArora_0-1681971010044.png

 

the main thing is you don't have any parameter in onSubmit where you get to know whether your assignment group has changed or not!

 

 

The best solution as per your scenario is using before-update business rule and I have tried in my PDI and it work really well

PrinceArora_1-1681972141673.png

 

Script:

 


if(!current.comments.changes()){
gs.addErrorMessage('Please insert some comments');
current.setAbortAction(true);
}

 

Please go ahead with this approach, otherwise we need to make multiple client scripts to handle this scenario and might be it is not possible too

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Hi! So this is actually locking the entire form even if I add into the Additional comments. I'm not sure if that happened on your end.

@cdavis22 

 

Have you added the above condition?

if(!current.comments.changes())

 

And make sure you are testing with the Additional comments not worknotes and just write the comments and save the record.

Yes, please see below. 

cdavis22_0-1681990248302.png

Once I change the assignment group I am not able to update the form, but it is still not accepting even after the comments are updated.

cdavis22_1-1681990338116.png

cdavis22_2-1681990426567.png

So I am not sure if i should add in g_form?

@cdavis22 

 

Don't post the comments, how the script get to know comments have been added, just type the comments as below and save the record, Once the comments have been posted you can not pick it and this is valid behaviour

 

PrinceArora_0-1681990612002.png

comments should be added, when assignment group has been changed otherwise the posted comments would n't be the part of your latest transaction, I hope you get my point!

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.