UI Action Prompt for save
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I have a UI Action then when click it calls a workflow which uses the task_ci table to get the approvers from the CIs. I noticed that if I add a CI to the configuration item field then click the UI action it is saving the records but not before the workflow fires so the CI is not in the task_ci table. How can I get the UI Action to prompt for a save similar to when clicking on the Risk assessment UI action in change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi there @Brian Lancaster
You can handle this by making your UI Action prompt the user to save before running the workflow. In the script, check if the record is new or modified and then use:
if (g_form.isModified()) {
if (confirm("You have unsaved changes. Save before proceeding?")) {
g_form.save();
} else {
return false;
}
}This makes the form is saved first, so your workflow picks up the latest CI data
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 2 weeks ago
Ok I have the following code in the system and it is doing the prompt and saving the form but it is not calling any of the server side scripts. Any thoughts? Not if I'm not going thought the prompts to save it works as expected.
function requestApproval() {
var isModified = g_form.modified;
if (isModified){
var answer = confirm("You have unsaved changes. Save before proceeding?");
if (answer){
g_form.save();
gsftSubmit(null, g_form.getFormElement(), 'request_dev_approval');
}
else{
return false;
}
}
gsftSubmit(null, g_form.getFormElement(), 'request_dev_approval');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
You can achieve this by turning your UI Action into a client first button where your script checks if the CI field has changed and forces a save first before the workflow fires, for example by checking g_form.isNewRecord() or checking if the CI field has been modified, then using g_form.save() (or gsftSubmit()) on the client, and only once the save completes you trigger your server side logic (workflow) via the UI Action.....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
