- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 08:49 AM
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.
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 09:16 AM
Hi
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:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 08:57 AM
if (current.additional_comments.nil()) {
gs.addErrorMessage("please add additional comments before cancelling the catalog task");
}
you can add this in the function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 09:30 AM
Hi Mr.
taskCancel();
function taskCancel() {
if(current.request_item.cat_item.u_task_cancellation == false){
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.getValue('request_item'))) {
ritm.setValue('stage', "Request Cancelled");
ritm.update();
if (current.additional_comments.nil()) {
gs.addErrorMessage("Please add Additional Comments before cancelling the Catalog Task");
}
}
}
current.state = '4';
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 09:07 AM
Hi
Follow the below steps, tested..perfectly working...
- Create UI Action
- Provide Action Name as "cancel_button"
- Check the Client Checkbox
- Set the OnClick value to cancelButton();
- Add the below script in the script section.
function cancelButton(){
g_form.setValue('state', '8'); //here 8 is my cancel state
if (g_form.getValue('comments') == '') {
//Remove any existing field message, set comments mandatory, and show a new field message
try {g_form.hideFieldMsg('comments');} catch(e) {}
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments','Reason is required while cancelling the incident','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_button'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
cancellButton();
function cancellButton(){
current.state = 8;
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 09:33 AM
Hi Mr. @Raghu Ram, we already have an existing UI Action and script for the CANCEL button. I just need to modify it to ensure 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 existing UI ACTION