Workspace client script UI Action is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 09:02 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 10:38 AM
You still want a new UI action for this...and it depends a bit on what module is originating the "Parent" and what type of record the "Child" is...
OOB, there is a workspace UI Action that creates an Incident from an Interaction record, which has this code that you can probably also use here...
var inc = new GlideRecord("incident");
inc.initialize();
inc.caller_id = current.opened_for;
inc.short_description = current.short_description;
if (gs.getProperty("com.snc.incident.create_from_interaction.save") === 'true') {
inc.work_notes = gs.getMessage('Incident created from Interaction {0}', current.number);
var incSysId = inc.insert();
if (incSysId) {
var interactionRelatedGR = new GlideRecord("interaction_related_record");
interactionRelatedGR.initialize();
interactionRelatedGR.interaction = current.sys_id;
interactionRelatedGR.document_table = 'incident';
interactionRelatedGR.document_id = incSysId;
interactionRelatedGR.insert();
}
}
action.openGlideRecord(inc);
You'll want to change the "Interaction" parts with your "sdmTaskForm"...and you'll need to replace the "Incident" parts with the type of record you are looking to create
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 10:42 AM
This is a server side code and I need to use client side code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 11:09 AM - edited 05-29-2023 11:11 AM
Is that a requirement of your business, specifically? -- or are you worried it won't work, because of that?
OOB, the UI action does need to write the interaction record to the server before the button is available...but after the interaction record is saved (assuming the parent record in your scenario is already saved in the associated table), the rest is in-client (it won't create the incident until you save/submit)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 11:18 AM
It is requirement of business.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 10:14 AM
Hi @Rekha20 ,
You are not seeing any value for win because g_aw.openRecord() returns none, refer to the screenshot below
If my answer has helped with your question, please mark it as correct and helpful
Thanks!