The CreatorCon Call for Content is officially open! Get started here.

action.setRedirectURL(current); Does not work in UI Action when executed from Agent Workspace

Igor Tsalyuk
Kilo Guru

We have a Request Approval UI Action on a Change Request form that moves the New state's request to Assess state or from Assess to Authorize. Also, this UI Action checks Planned Start/End Dates that they are not in a Blackout schedule, and if they are, an error message shows up, and the state is getting reset to New. This is accomplished via Server side script, and the way request is getting put back by the use of action.setRedirectURL(current) function. It works great while you are in the Desktop interface, but when you are in the Agent Workspace, this function does not work at all. It would be great if someone could help me figure out what to do here. I am very new to Agent Workspace.

 

Here is UI Action:

Name: Request Approval

Table: Change Request

Client: Checked

Form Button: Checked

Show Update: Checked

Onclick: moveToAssess();

 

Script:

function moveToAssess() {

 

    var ga = new GlideAjax("ChangeRequestStateHandlerAjax");

    ga.addParam("sysparm_name", "getNextStateValues");

    ga.addParam("sysparm_change_sys_id", g_form.getUniqueValue());

    ga.addParam("sysparm_change_type", g_form.getValue("type"));

    ga.getXMLAnswer(function(stateValues) {

        var returnedStates = stateValues.evalJSON();

        g_form.setValue("state", returnedStates[0]);

        //if (current.sys_domain_path != "APPROVALNOFRZ" && current.sys_domain_path != "NOAPPROVALFRZ") {

        //if (current.sys_domain_path != "BSAPPROVALNOFRZ" && current.sys_domain_path != "BSAPPROVALFRZ") {

        g_form.setValue("sys_domain_path", "/");

        //}

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

    });

}

 

if (typeof window == 'undefined')

    updateAndRedirect();

 

function updateAndRedirect() {

//Check for Blackout Conflicts

var blackout_conflict = new GlideRecord('conflict');

blackout_conflict.addQuery('change', current.sys_id);

blackout_conflict.addQuery('type', 'blackout');

blackout_conflict.query();

if (blackout_conflict.next()) {

gs.addErrorMessage('You have scheduled this Change inside a Blackout Window. Please update the planned start/end dates to fall outside a Blackout Window or change the Change Request Type to "Expedited" to proceed.');

action.setRedirectURL(current);

return false;

}

 

current.update();

    action.setRedirectURL(current);

}

6 REPLIES 6

Hi,

the script should be only client side and no server side

Regards
Ankur

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

@Igor Tsalyuk 

This worked well for me

I just created UI Action which will redirect to same form in agent workspace

Just add your code for Ajax

Workspace client script

function onClick(g_form) {

	// your GlideAjax here to update records

	// your redirection here

	var url = '/now/workspace/agent/record/' + g_form.getTableName() + '/' + g_form.getUniqueValue();
	var win = top.window.open(url, '_self');
	win.focus();

}

Regards
Ankur

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