How to open a new tab of Catalog Item in Workspace.

Community Alums
Not applicable

Hi,

 

I have a UI action which should be visible in HR agent workspace in HR case record, which will open a new tab in workspace itself. The link is of a catalog item where I am also passing a sys_id of the current HR case.

 

I have written below code in script section, it is working fine in the native UI:

 

Onclick: redirectURL()

 

function redirectURL() {
    var sysId = g_form.getUniqueValue();
    var url = 'uep?id=sc_cat_item&table=sc_cat_item&sys_id=e288e2fc975c5e94b7b2711e6253af42' + '&sysparm_sys_id=' + sysId;

    g_navigation.open(url, '_blank');
}
 ---------------------------------------------------------------------------------------------------------------------------
But the workspace code is not working, means clicking does not do any action:
 

Workspace Form Button: True

Workspace Form Menu: True

Format for Configurable Workspace: True

 
function redirectURL() {
    var sysId = g_form.getUniqueValue();
    var url = 'now/hr/agent/home?id=sc_cat_item&table=sc_cat_item&sys_id=e288e2fc975c5e94b7b2711e6253af42' + '&sysparm_sys_id=' + sysId;

    g_aw.open(url, '_blank');
}
1 ACCEPTED SOLUTION

Shruti
Mega Sage
Mega Sage

Hi 

Try this

 

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 = "sn_hr_core_case";
        params.sysparm_parent_sys_id = g_form.getUniqueValue();
        g_service_catalog.openCatalogItem('sc_cat_item','e288e2fc975c5e94b7b2711e6253af42', '-1', params);
    });
}

View solution in original post

2 REPLIES 2

Shruti
Mega Sage
Mega Sage

Hi 

Try this

 

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 = "sn_hr_core_case";
        params.sysparm_parent_sys_id = g_form.getUniqueValue();
        g_service_catalog.openCatalogItem('sc_cat_item','e288e2fc975c5e94b7b2711e6253af42', '-1', params);
    });
}

Community Alums
Not applicable

Thanks, the code is working and opening new tab in workspace itself but now the problem is I have one variable created and in that I am storing value of the sys_id through catalog client script like this :

 

    var link = parent.window.location.href;
    var sysIdOfHRcase = new URLSearchParams(link).get("sysparm_sys_id");

    g_form.setValue('sys_id', sysIdOfHRcase); // 'sys_id' is a variable to store sys_id of the hr case
----------------------------------------------------------------------------------------------------------------------
My query is how we can achieve same population of sys_id in the variable of the catalog item in the workspace also. Please help if you have any idea.