Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Action Prompt for save

Brian Lancaster
Kilo Patron

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?

3 REPLIES 3

Its_Azar
Tera Guru
Tera Guru

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

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

@Its_Azar 

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');
}

 

 

kaushal_snow
Giga Sage

@Brian Lancaster ,

 

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.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/