Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Workspace client script UI Action is not working

Rekha20
Tera Contributor

Hi All,

 

I have created a client callable UI action which is not wokring for workspace. Workspace client script code is below:

 

function onClick(g_form) {
var currentRecordSysId = g_form.getUniqueValue();
var caseNumber = g_form.getValue('number');
alert(caseNumber);
var assignedTo = g_form.getValue('sys_created_by');
var assignmentGroup = g_form.getValue('assignment_group');
var shortDescription = g_form.getValue('short_description');
var description = g_form.getValue('description');
var account = g_form.getValue('account');
var urgency = g_form.getValue('urgency');
alert("Clicked on the UI action");
var query = '';
query = query + '^u_parent_case=' + g_form.getUniqueValue();
g_aw.openRecord('sn_customerservice_sdm_management_task', '-1', {
'query': query
});

alert("After opening the record"); // Added for debugging purposes

var win = g_aw.openRecord();
alert(win); // Added for debugging purposes
win.onload = function() {
alert("Clicked on the UI action under the function");
var sdmTaskForm = win.g_form;
alert(sdmTaskForm);

sdmTaskForm.setValue('u_parent_case', currentRecordSysId);
sdmTaskForm.setValue('assignment_group', assignmentGroup);
sdmTaskForm.setValue('assigned_to', assignedTo);
sdmTaskForm.setValue('short_description', shortDescription);
sdmTaskForm.setValue('description', description);
sdmTaskForm.setValue('u_account_name', account);
sdmTaskForm.setValue('urgency', urgency);
sdmTaskForm.setValue('u_choice_8', '1');
sdmTaskForm.setValue('u_type', 'reactive');
sdmTaskForm.setValue('u_time_worked', '1');
sdmTaskForm.setValue('u_sdm_action_taken_to_address_issue', 'test');
sdmTaskForm.setValue('u_sdm_outstanding_pending_nextactions', 'test');
sdmTaskForm.setValue('u_action_being_requested_of_sdm', 'test');

var glideAjax = new GlideAjax('CustomUtils');
glideAjax.addParam('sysparm_name', 'getEscalationNumbers');
glideAjax.addParam('sysparm_source_record_sysid', currentRecordSysId);
glideAjax.getXMLAnswer(function(response) {
var escalations = response.split(',');

sdmTaskForm.setValue('u_mod_escalation', escalations.join(','));

sdmTaskForm.save(); // Trigger form submission
});
};
}

 

 

This is not triggering alert alert(win);

 

please help me with this.

 

Thanks,

11 REPLIES 11

jMarshal
Mega Sage

Have you already tried to add

var win = g_aw.openRecord();

win = win.toString();

...to see if you get the alert and what it contains?

Rekha20
Tera Contributor

Hi @jMarshal  Thanks for your response.

Yes var win = g_aw.openRecord();

alert(win) is giving as undefined and after changing to string alert is not triggering

hmmm...it doesn't seem like you are using openRecord() correctly, perhaps...it seems very specific, requiring input arguments and performing a specific function in aw. GlideAgentWorkspace (g_aw) | ServiceNow Developers

"openRecord()" is a display function not something that allows you to specify values...are trying to get this to open in a new tab, with pre-populated values (which happen to not be the default), which the agent/user is then supposed to submit (separately)?

...it seems like that is what you are trying to do here...

The "openRecord" and "closeRecord" functions in g_aw are specific to displaying on a tab and have nothing to do with creating/saving/activating/modifying/closing/changing-state with values on a record.

Rekha20
Tera Contributor

Hi @jMarshal  Yes then how should I do that. 

I need to set value from parent record to child record. New form that is opening when clicking on button created on parent record. and child record has a field u_parent_case which refers to parent record.

 

Please help me with this.