Need to make Additional Comment field mandatory ONLY IF the SCTASK is being canceled.

Anastasia Ty-Ch
Tera Contributor

Hi guys. I need help in with my requirements.

Currently, user can cancel the SCTASK without adding a note on why it is being canceled.

find_real_file.png

 

We need to make sure that the ADDITIONAL COMMENTS field will become MANDATORY ONLY IF the SCTASK is being canceled. It should require users to add notes on why this is being canceled.

If the user did not put any comments, they can't cancel the SCTASK and if they insist, there should be a warning that the Additional Comments field is MANDATORY and will require notes.

This is our SCRIPT of the UI Action CANCEL. Can someone help me with the requirements?

find_real_file.png

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Anastasia Ty-Chen 

Also would like to share here the UI action can itself execute as both Client and Server side methods.

Please refer the below link which explains this very clearly:

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

So now for your requirement, you can update your UI Action as below:

1) Give a action name say "cancelTask"

2) Click on the check box "Client" on UI Action form

3) Give a valid on click function such as "cancelCatalogTask()"

4) Now update your current UI Action script as below:

function cancelCatalogTask() {
    g_form.setMandatory('comments',true);
    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'cancelTask'); //MUST call the 'Action name' set in this UI Action
} 

//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    runBusRuleCode();

//Server-side function
function runBusRuleCode() {

// Add your current code here which is supposed to run on Server side
}

Sharing the screenshot as well for reference on the changes you need to do:

find_real_file.png

Have shared both the methods with you and both should work. Please try and let me know if you have a query.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

10 REPLIES 10

Thank you Mr. @shloke04 this is working now. Thank you so much