The CreatorCon Call for Content is officially open! Get started here.

Agent Workspace Issue

Michael94
Tera Contributor

Hello,

I'm trying to create a UI action that export an HR case record in both the case form in the native UI and Agent Workspace. The UI action works correctly in the native UI but does not function properly in Agent Workspace. 

 

 

20 REPLIES 20

Michael94
Tera Contributor

here is my script include (client callable): 

 

var validateService = Class.create();
validateService.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	getViewName: function() {
		var hrService = this.getParameter('sysparm_service');
		var viewName = '';
		var grService = new GlideRecord("sn_hr_core_service");
		grService.get(hrService.toString());
		if(grService.name == "Extra"){
			viewName = 'extra_view';}
		else {
			viewName = 'old_extra_view';}
		return viewName;},
   type: 'validateService'
});

 

Note: this is working as expected in native. 

 

Hi @Michael94 
I just found that the table name which you've used in the workspace UI script is incorrect.

OOB HR case table name is "sn_hr_core_case" but you are using "sn_hr_case".
Could you please validate the table name?

var url = instanceURL +'sn_hr_core_case.do?PDF&sys_id=' +  sysparm_sys_id+'&sysparm_view='+sysparm_view; ​

 


 

Michael94
Tera Contributor

Yes, I had fixed it earlier and that's not the issue. 

Michael94
Tera Contributor

@Ankur Bawiskar and @J Siva, I think the issue lies in the Ajax call within the Workspace client script, as it is not returning any view value. If I remove the Ajax call and instead directly specify a view (e.g., viewName = 'extra_view') while handling the PDF process entirely within the workspace client script, how should the script be structured? 

@Michael94 

why not use getReference with callback instead of GlideAjax

OR

You can use GlideRecord with call back

function onClick(g_form) {

    var hrService = g_form.getValue('hr_service');
    var gr = new GlideRecord("sn_hr_core_service");
    gr.addQuery("sys_id", hrService);
    gr.query(checkRecord);

    function checkRecord(gr) {
        if (gr.next()) {
            var sysparm_view = '';
            if (gr.name.toString() == "Extra") {
                sysparm_view = 'extra_view';
            } else {
                sysparm_view = 'old_extra_view';
            }
            var sysparm_sys_id = g_form.getUniqueValue().toString();
            var url = '/' + instanceURL + 'sn_hr_core_case.do?PDF&sys_id=' + sysparm_sys_id + '&sysparm_view=' + sysparm_view;
            top.window.open(url, '_blank');
        }
    }

OR using location.hostname

function onClick(g_form) {

    var hrService = g_form.getValue('hr_service');
    var gr = new GlideRecord("sn_hr_core_service");
    gr.addQuery("sys_id", hrService);
    gr.query(checkRecord);

    function checkRecord(gr) {
        if (gr.next()) {
            var instanceURL = "https://" + location.hostname + "/";
            var sysparm_view = '';
            if (gr.name.toString() == "Extra") {
                sysparm_view = 'extra_view';
            } else {
                sysparm_view = 'old_extra_view';
            }
            var sysparm_sys_id = g_form.getUniqueValue().toString();
            var url = instanceURL + 'sn_hr_core_case.do?PDF&sys_id=' + sysparm_sys_id + '&sysparm_view=' + sysparm_view;
            top.window.open(url, '_blank');
        }
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

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