How to Save a Form When a UI Action is Clicked then Continue the Script Logic

charbree05
Tera Expert

I have a requirement to adjust an existing workspace UI Action so that it can be utilized from a new record. However, the logic within the client script of the UI Action requires the sys_id of the current record and since the record does not exist yet, it has no sys_id.

 

Adding g_form.save() at the beginning of the script does save the form but it causes the page to reload and prevents the rest of the of functionality in the script from running. In this specific UI action, a modal is supposed to open when clicked. Is it possible to save the current form in the UI Action without causing the page to reload so that the rest of the logic in the script can occur?

 

 

1 REPLY 1

Deepak Shaerma
Kilo Sage

hi @charbree05 

you should check if the ui Action in the workspace supports an async save with a callback.

g_form.save(null, function() {
  // Now you have a sys_id because form is saved, open your modal here
  openModal();
});

If this works, great. This pattern saves the form and after the save complete, runs the callback (no page reload).

 

// Example Workspace UI Action script
(async function() {
  // Check if record is new (no sys_id)
  if (!g_form.getUniqueValue()) {
    try {
      await g_form.saveRecord();
      // Now record is saved, sys_id is available
      openModal();
    } catch (err) {
      console.error('Save failed', err);
    }
  } else {
    // existing record, directly open modal
    openModal();
  }
})();

function openModal() {
  // Your modal opening logic here
  // e.g., Workspace modal API call or GlideModal
}

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Deepak Sharma