Client-side equivalent of current.update?

peterraeves
Mega Guru

We created our own application and wanted to create something similar to the UI Action "Create Problem" (or change, etc). After the button is pressed, a new record should be created and both should be linked to each other through the reference field. We would like to have these buttons available on both sides and on new records as well. In the one direction the code is pretty straightforward:

current.update(); //Checks for mandatory fields. Stops when not filled in, continues when filled in.

var obj = new MyObject();

obj.createOtherRecord(current);

In the other direction, we need additional information. Here I'm stuck.

I created a UI Page that asks for the information and finally calls the above code with the additional parameter

var obj = new MyObject();

obj.createOtherRecord(current, parameter);

Putting the update right before that is not good. Current isn't available and it's way too late to check for mandatory fields then. So we want to put it as the first line of code in the UI Action, before the UI Page gets called and if an error occurs, the UI Page should not be opened. But as this is a Client-Side UI Action, the only thing I know of is using "g_form.submit()", but that doesn't seem to show pretty alerts about empty mandatory fields. Using "gsftSubmit" works partially.

gsftSubmit(null, g_form.getFormElement(), '');

if(typeof window != 'undefined')

  return;

/* Script for opening the UI Page */

The above code stops correctly when mandatory fields are not filled in and warns me about it. When all fields are filled in it somehow complains that "Changes have been made to the record and will not be saved", which is not what I wanted to see...

9 REPLIES 9

Modifying the order of the client scripts could help


Same effect


Hi @peterraeves,

I'm wondering if you have found a solution to saving the record in UI action script?  I need to achieve the same thing (saving the record, then showing a popup).

Thanks,
Jenny

Hi Jenny, 

did you ever find a solution to this issue? I'm having the same requirements.

Thanks,

Bart

 

Hi Bart,

in client script i.e. onChange you can use g_form.save() to save the current record with the values

Regards

Ankur

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