Client Script not working in Agent Workspace

SN Rookie
Giga Expert

Most of the client scripts which are working in normal default view of forms aren't working in Agent Workspace. 

For example - the below script is not working. How can we ensure all client scripts work fine in AW?

function onLoad()
{
	var isAdmin = g_user.hasRole('admin');
	var state = g_form.getValue('state');
	if (!isAdmin )
		{
		if(state != 3){
			g_form.removeOption('state', '3');
		}
	}
}

1 ACCEPTED SOLUTION


Hi SN Rookie,

 

'g_user.getUserID()' is not supported in Agent workspace or service portal but does in the normal SN platform as some APIs are only supported in Desktop UI(platform).
It is recommended to use 'g_user.userID' as it works in every application.

 

You can also refer to this doc for all the supported APIs :
https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/reference/c...

View solution in original post

7 REPLIES 7


Hi SN Rookie,

 

'g_user.getUserID()' is not supported in Agent workspace or service portal but does in the normal SN platform as some APIs are only supported in Desktop UI(platform).
It is recommended to use 'g_user.userID' as it works in every application.

 

You can also refer to this doc for all the supported APIs :
https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/reference/c...

if i see your question and read it again, you are using g_user.hasRole() 

and it will work on agent work space. 

 

I tested your script which you have posted on the question and it's working.

 

agreed on g_user.getUserID() method , that will not work BUT if you will use g_user.userID that will work on native ui as well as work-space. 

 

shaik riyaz1
Tera Contributor

Hi @Sanbir Singh1  @SN Rookie @Harsh Vardhan ,

 

I got the same issue like my script is working in default view but not in agent workspace..

 

When "ServiceNow" choice is selected in the "HR system affected" question. Present these options on the "Topic" Question (choices)

- Live Chat Issue
- Virtual Agent/ Virtual Agent Dialogues
- HR Agent Workspace Functionality
- Reporting and Dashboards
- Knowledge Articles
- HR Case Management Model Query
- ServiceNow HRSD Training Content


- Request Forms & Service Portal related issue

I wrote a client script for this which is working fine in default view but it is not working in "workspace view" ...can someone please help on what i'm missing??

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var optionsAll = [
'-- None --',
'Live Chat Issue',
'Virtual Agent/ Virtual Agent Dialogues',
'HR Agent Workspace Functionality',
'Reporting and Dashboards',
'Knowledge Articles',
'HR Case Management Model Query',
'ServiceNow HRSD Training Content',
'Request Forms & Service Portal related issue',
'HR Process design',
'HR AWS',
'HR Groups',
'Request Forms',
'Service Portal menus and other aspects',
'SOPs / Work Instructions',
'Training content',
'Virtual Agent',
'Other'
];
var optionsValuesAll = [
'',
'live_chat_issue',
'virtual_agent_virtual_agent_dialogues',
'hr_agent_workspace_functionality',
'reporting_and_dashboards',
'knowledge_articles',
'hr_case_management_model_query',
'servicenow_hrsd_training_content',
'request_forms_service_portal',
'hr_process_design',
'hr_aws',
'hr_groups',
'request_forms',
'service_portal_menus_and_other_aspects',
'sop_work_instructions',
'training_content',
'virtual_agent',
'other'
];
var hrService = g_form.getValue('u_hr_system_affected');
var topicField = g_form.getControl('u_topic');
topicField.options.length = 0;
if (hrService == 'service_now') {
for (var i = 0; i < 9; i++) {
var option = document.createElement('option');
option.value = optionsValuesAll[i];
option.text = optionsAll[i];
topicField.add(option);
}
} else if (hrService != 'service_now' || hrService == '' || hrService == null) {
for (var j = 0; j < optionsAll.length; j++) {
var optionAll = document.createElement('option');
optionAll.value = optionsValuesAll[j];
optionAll.text = optionsAll[j];
topicField.add(optionAll);
}
}
}