- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 02:31 AM
Hi Every one,
when i click the cancel UI action an Active SIR record without providing work notes
in that Cancel UI action i have created the scripts to populated the error message, the error message is shown but it's gone when the page is fully completely loaded, I want a warning message banner should appear on top of form and stay there after page is completely loaded, below is the UI script, any suggestion please.
if (current.work_notes == "") {
gs.addErrorMessage("Worknotes mandatory. Please write cancellation reason in the worknotes.");
//action.setRedirectURL(current);
}else {
var wf = new global.Workflow();
wf.cancel(current);
current.state = 7;
current.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 04:56 AM
Hi @DeepikaR1661877 ,
Please try the below code:
function errorOnEmptyWorkNote() {
if (g_form.getValue('work_notes') == "") {
g_form.addErrorMessage("Worknotes mandatory. Please write cancellation reason in the worknotes.");
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel_action');
}
if (typeof window == 'undefined')
Cancel();
function Cancel() {
var wf = new global.Workflow();
wf.cancel(current);
current.state = 7;
current.update();
}
If you find this helpful, please mark as Correct or Helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 02:38 AM
@DeepikaR1661877 Instead of trying to use gs.addErrorMessage(), make your UI Action client callable by checking the client checkbox and show the error message via g_form.addErrorMessage(); This will trigger the error message on the client side without reloading the form.
To know more about how to execute client and server side code via UI Action, please refer to this article https://www.servicenow.com/community/itsm-articles/client-side-and-server-side-code-in-one-ui-action...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 03:21 AM
Hi @Sandeep Rajput ,
I have tried the above method, when i am click the cancel UI action it's not working that means it's not showing any action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 03:51 AM
Hi @DeepikaR1661877 ,
In your UI Action, please select the "Client" checkbox and set the OnClick field to the function that contains the client script, which will be triggered when the Cancel button is clicked.
"If you found my answer helpful, please like and mark this response correct by clicking on "Accept as Solution". It helps others find the solution more easily and supports the community!"
Thanks,
Prudvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 04:56 AM
Hi @DeepikaR1661877 ,
Please try the below code:
function errorOnEmptyWorkNote() {
if (g_form.getValue('work_notes') == "") {
g_form.addErrorMessage("Worknotes mandatory. Please write cancellation reason in the worknotes.");
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel_action');
}
if (typeof window == 'undefined')
Cancel();
function Cancel() {
var wf = new global.Workflow();
wf.cancel(current);
current.state = 7;
current.update();
}
If you find this helpful, please mark as Correct or Helpful.