Save form in client script

pramodkumar
Tera Expert

Hi All,

I am using a on change client script on priority field (incident) in workspace to show few fields using modal. Once all fields are filled and clicked ok, the information is passed to a script include to send few notifications. But the form is not saving. Do I need to save record in client script or script include?

 

 

Thanks!

4 REPLIES 4

Rafael Batistot
Tera Sage

Hi @pramodkumar 

 

kindly share yours scrips to give more assertive assistance? 

thank you 

Ankur Bawiskar
Tera Patron
Tera Patron

@pramodkumar 

what's the business requirement for this?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Bhimashankar H
Mega Sage

Hi @pramodkumar ,

 

When you use an onChange client script in ServiceNow Workspace to display a modal, collect additional info, and then trigger a Script Include for notifications, you may notice the incident form does not automatically save after the workflow completes. 

  • Workspace client scripts do not automatically save the record when fields are changed, modals are submitted, or notifications are sent via Script Includes.

  • Script Includes always run server-side and do not have access to the active form in the user’s browser session, so they cannot directly save the record.

You should trigger the save action from your client script. The user's browser and UI session manages the current state; a Script Include can’t save the form the user is editing unless you pass all the latest data in the request.

use the following approach in your client script after processing the modal and before or after calling your Script Include (depending on logic). 

// Example: Save the current form in Workspace
g_form.save();

If you want to call the Script Include after saving (to ensure all data is committed), consider using a GlideAjax callback.

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & ' Correct' Thanks!

Bhimashankar H
Mega Sage

Hi @pramodkumar ,

 

I hope you saw my reply. 


If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. It will help future readers as well having similar kind of questions and close the thread.

Thanks,
Bhimashankar H