Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

OnSubmit Client Script - Force Mandatory

jstocton
Kilo Expert

I have the following use case:  

On the change_task form, the close_notes will be mandatory OnSubmit -- IF -- the business_service field on the parent change_request STARTSWITH SAP(space).

I was going to do this as a UI Policy, but there is no way to make the field mandatory on change or on submit.  I am really perplexed and have not seen any good examples of how to get to the parent change record and validate the contents of a field.  I know this is simple but just can't seem to make it work.

1 ACCEPTED SOLUTION

So in that case you can do something like this:

1. Create a Display business rule and capture the value of business service in g_scratchpad variable. Your BR would like this.

Display BR

Script:

(function executeRule(current, previous /*null when async*/) {

var ciName = current.parent.cmdb_ci.getDisplayValue(); //change cmb_ci to your Business service Name
g_scratchpad.ciName = ciName;

})(current, previous);

 

2. Use the scratchpad value in your OnSubmit Client Script:

function onSubmit() {
alert(g_scratchpad.ciName);
var str = g_scratchpad.ciName;
if(str.substring(0,4) == 'bond'){ //change bond to 'SAP '
alert('Cannot happen');
g_form.setMandatory('description',true); // replace description with your required field value
return false;
}
}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

10 REPLIES 10

Glad that i was able to help. Cheers. Happy learning 🙂


Please mark my response as correct and helpful if it helped solved your question.
-Thanks