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

Omkar Mone
Mega Sage

Hello,

 

Just to confirm, Can you try to give a static link just to check if this works on Workspace. Something like this - action.setRedirectURL("www.google.com");

 

NOTE:-

  • The current object is not available for conditions on a list context menu. The List context menu option is selected. Any use of current on these actions is ignored.

 

 

Regards,

Omkar

Hi Omkar, thank you for trying :). Yes action.setRedirecURL does not work in Agent workspace.

Ankur Bawiskar
Tera Patron
Tera Patron

@Igor Tsalyuk 

you will have to use client side UI action only as action.setRedirectURL() is not supported in agent workspace

you will have to use workspace client script and update the record using GlideAjax

then put the code to redirect to current record

Sample workspace client script

function onClick(g_form) {

	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]);
		g_form.setValue("sys_domain_path", "/");

		//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()) {

			alert('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.');
			return false;
		}
		else{
			var url = '/' + g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue();
			var win = top.window.open(url, '_blank');
			win.focus();
		}
	});
}

Regards
Ankur

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

Thank you, Ankur. I think you have some mix-up of Client and Server-side code, but either way, it does not work :(.