The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Call a UI Action from a Client Script to open a Change

RWeathersby1
Kilo Explorer

**I'm sure this has been done, before just can't find anything on the forum so I'm asking.**

I am trying to call a UI Action from a Client Script. I have a onChange Client Script running from the Incident table that if the 'confirm' value is True I'd like to automatically open a related Change record. But it's not working...thoughts?

Here's the code that I wrote that's not working.

function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '7' && !isLoading && g_form.getValue('rfc')=='') {
var rfc = g_form.getReference('rfc');
var answer = confirm('Was this Incident resolved by a Change? If yes press OK to create a Change Record. If No press Cancel.')
//force the Resolved by Change to Mandatory if OK
if (answer == true)
gsftSubmit(null, g_form.getFormElement('name'), 'Create Change');
else
g_form.setMandatory('rfc', false);
return;
}
}

13 REPLIES 13

Jace Benson
Mega Sage

Is your action name called, 'Create Change' or something like 'create_change'?

Here's a call oob that does what your looking for;


gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
(source demo20)


I tried what you mentioned but it still isn't working. ANd yes the action is 'create_change'. I've tried it both ways but it only returns me to the Incident queue. Not sure what I'm doing wrong.


Does it create the change record?
If you want to redirect the user to the newly created change record you would do something like this in your UI action.....
//creating the change record
var ch = new GlideRecord('change');
....
....
....
ch.insert();
action.setRedirectURL(ch);// to redirect the the user to the newly created change record.


I tried adding it to the client script and it doesn't work.