Having some problems with Client script used in a Button click event

ChristLaplante
Tera Contributor

Hi,

 

We are currently planning a deploy of Next Experience UI and with that that move from Agent Workspace to Service Operations Workspace.

 

We want to create a custom "Reassign" modal for our record page "SRP Record" (Vanconver patch 7) that is available for 

We created a custom page to test the behavior. We tried it before linking it as modalContainerViewport on the SRP Record macrocomponent, everything is fine (Because the "Close modal", is not available in this format.)

 

Here's the content:

ChristLaplante_0-1714395141635.png

We tried to chain 3 events to the button click, but it seems the "Close modal" always bypass the other events.

First event:

Set a work notes depending if the checkbox is "Checked" or not.

Second Event:

Form save

Third event:

Modal close

 

We tried to merge those actions within a client script, but it seems the "Save" action is never launch...

How can we be able to achieve that.

It as our only problem to solve before entering Users testing.

 

Here is the script we created:

                 //  If work notes are empty and checkbox is checked
	if(api.data.form_main_record.form.fields.work_notes.value == "" && api.state.bypassNotes == true)
	{
                     //  Add an automatic work notes that the issue is already discussed between teams
		api.data.form_main_record.form.fields.work_notes.value = "Je confirme que la réassignation de cette demande a déjà été discutée ou qu'il s'agit d'un transfert intraéquipe.";
	}
	else if (api.data.form_main_record.form.fields.work_notes.value != "" && api.state.bypassNotes == true)
	{
                  // Append the same automatic work notes with a carriage return after the user work notes entered
		api.data.form_main_record.form.fields.work_notes.value += "\nJe confirme que la réassignation de cette demande a déjà été discutée ou qu'il s'agit d'un transfert intraéquipe.";
	}
              // Save the form
        api.data.form_main_record.save();
             // Close the named modal
	helpers.modal.close("[component-id$='assignation']");

What are we doing wrong?

 

Thanks

Christian Laplante

IT technology analyst

ServiceNow SysAdmin

Université de Sherbrooke



Christian Laplante
IT Analyst, ITSM SysAdmin
Université de Sherbrooke
Québec, Canada
1 REPLY 1

Brad Tilton
ServiceNow Employee
ServiceNow Employee

The main issues you're running into here is that the data resource results are read only. The data resource is just fetching server data. If it's a form controller data resource it should have its own events to set values on the record. If this isn't using the form controller you can use an update records data resource to set values.