Agent Workspace: How to Pass and Get parameters via URL in Agent Workspace?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2019 02:38 AM
Dear All,
We have an existing setup in ServiceNow to auto populate Requested for & Requested By variables in catalog items when created from an incident.
When Agent click on 'Create Request' in an incident form, we pass the following parameter:
var url = "catalog_home.do?sysparm_view=catalog_default&sysparm_processing_hint=setfield:request.parent=";
url += current.sys_id;
and redirect to above URL.
We have an onload catalog script to get the URL Parameter:
function onLoad() {
var gURL = new GlideURL();
gURL.setFromCurrent();
var value1 = gURL.getParam("sysparm_processing_hint");
var str = value1.replace("setfield:request.parent%3d", "");
var ga1 = new GlideAjax('get_group');
ga1.addParam('sysparm_name', 'Sendincsysid');
ga1.addParam('sysparm_incSysID', str);
ga1.getXML(responseSetVariables);
function responseSetVariables(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != "" || answer != null) {
var myarray = answer.split(',');
for (var i = 0; i < myarray.length; i++) {
g_form.setValue('requested_by', myarray[0]);
g_form.setValue('u_on_behalf_of', myarray[1]);
}
}
}
}
Same code is not working on Agent Workspace.
We have a new UI Action 'Create Request' on Incident table for agent workspace (Workspace Form Menu is true) available on New York version.
I am unable to pass and get the parameter on script using var gURL = new GlideURL(); system stops script execution. (Also agent workspace URL is embaded and parameter automatically add ASCII code on URL.)
Thanks in advance!
Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2019 04:03 AM
There is an OOTB UI Action 'Create Request' added for agent workspace.
https://instance.service-now.com/sys_ui_action.do?sys_id=084959b087081300e3010cf888cb0b0e
function onClick() {
var result = g_form.submit('sysverb_ws_save');
if (!result) {
//failed form submission
return;
}
result.then(function() {
var params ={};
params.sysparm_parent_table = "incident";
params.sysparm_parent_sys_id = g_form.getUniqueValue();
g_service_catalog.openCatalogItem('sc_cat_item', '-1', params);
});
}
When I click on this button, it redirects to catalog page to select item.
Here I want to populate requested by & requested for from incident.
I want to use params.sysparm_parent_sys_id = g_form.getUniqueValue(); to populate this info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 12:59 PM
Hello ashwanikumar,
did you have any luck achieving this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 01:30 PM
Hey Ashwanikumar,
Any luck achieving this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 06:35 AM
Hi,
I also tried very hard to make it work by getting the parameters from the URL but i did not succeed. So i tried several other method's and found one that's pretty simply and worked for me.
Step 1
Create a Script Include:
- Name: AgentWorkspaceUtilsGA
- Client Callable:True
- Accessible from: All application scopes
var AgentWorkspaceUtilsGA= Class.create();
AgentWorkspaceUtilsGA.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setAgentWorkspaceRequestedFor: function() {
var contactID = this.getParameter('case_contact_id');
//Add contact sys id in session
gs.getSession().putClientData('request_requested_for', contactID);
},
clearAgentWorkspaceRequestedFor: function() {
//Clear contact sys id in session
gs.getSession().clearClientData('request_requested_for');
},
type: 'AgentWorkspaceUtilsGA'
});
Step 2
Edit the OOTB UI Action 'Create Request' added for agent workspace. (Or create a new one)
https://instance.service-now.com/sys_ui_action.do?sys_id=084959b087081300e3010cf888cb0b0e
function onClick() {
var params = {};
params.sysparm_parent_table = "sn_customerservice_case";
params.sysparm_parent_sys_id = g_form.getUniqueValue();
//Add contact ID to Session so it can be used in setting the Requested for in the catelog item
var contactID = g_form.getValue('contact');
var request = new GlideAjax('AgentWorkspaceUtilsGA');
request.addParam('sysparm_name', 'setAgentWorkspaceRequestedFor');
request.addParam('case_contact_id', contactID);
request.getXMLAnswer(function(answer){
onSubmitAfterSessionPut(params);
});
}
function onSubmitAfterSessionPut(params) {
var result = g_form.submit('sysverb_ws_save');
if (!result) {
//failed form submission
return;
}
result.then(function() {
g_service_catalog.openCatalogItem('sc_cat_item', '-1', params);
});
}
Step 3
Create a or edit you're existing client script for setting the requested for field:
- Type: On load
- UI type: All
- Applies on a Catalog Item view: True
- Isolate script: True
function onLoad() {
var requested_for = g_user.getClientData('request_requested_for');
if(requested_for != '') {
g_form.setValue('requested_for', requested_for);
}
//Clear client session data
var clearSesion = new GlideAjax('AgentWorkspaceUtilsGA');
clearSesion.addParam('sysparm_name', 'clearAgentWorkspaceRequestedFor');
clearSesion.getXMLAnswer(function(answer){ });
}
I have only one field to set. If you have more values/fields then just pass them to the GlideAjax script and add them to the Session.
I hope this helps 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 08:01 AM
Hi Stefan,
I've already done that. You need to clear the session after the request is submitted, or the data will be populated from session into the request variables every time a new request is opened.
To the same script include add below lines of code
clearAgentSession: function(){
session.clearClientData('Your_session_variable');
}
create a onSubmit Client script on the request:
function onSubmit() {
var ga = new GlideAjax('Script_include_name');
ga.addParam('sysparm_name', 'clearAgentSession');
ga.getXML(ClearNewUserInformation);
function ClearNewUserInformation(response) {}
}
But there is a catch doing this,
If the Agent clicks on the UI Action to create request and abandons the request without submitting, the data stored in the session will be there in the session until user session ends.