Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

UI Action codes don't work in Workspace ?

sieusaopolo15
Giga Sage

I have this code in my UI Action

//gs.setRedirect("cmdb_m2m_model_substitute.do?sys_id=-1&sysparm_query=model=" + current.sys_id);
var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set('sysparm_m2m_ref', 'cmdb_m2m_model_substitute');
uri.set('sysparm_stack', 'no');
uri.set('sysparm_collectionID', current.sys_id);
uri.set('sysparm_collection_key', 'model');
uri.set('sysparm_collection_related_file', 'cmdb_model');
uri.set('sysparm_collection_related_field', 'substitute');
action.setRedirectURL(uri.toString('sys_m2m_template.do'));
gs.setReturn(current.getLink(true));

It works perfectly on classic form UI but when I add the button to Workspace this function doesn't seem to work so I opened up the browser log and check there is a message "Unhandled redirect type" and give me back the object

{
    "type": "FILE",
    "url": "sys_m2m_template.do?api=api&sysparm_collectionID=a9795bb0db5c7c90981b5baed39619c7&sysparm_collection_key=model&sysparm_collection_related_field=substitute&sysparm_collection_related_file=cmdb_model&sysparm_m2m_ref=cmdb_m2m_model_substitute&sysparm_stack=no&sysparm_sys_id=a9795bb0db5c7c90981b5baed39619c7&sysparm_table=cmdb_hardware_product_model",
    "query_params": {
        "sysparm_table": "cmdb_hardware_product_model",
        "sysparm_stack": "no",
        "sysparm_collection_related_file": "cmdb_model",
        "sysparm_sys_id": "a9795bb0db5c7c90981b5baed39619c7",
        "sysparm_m2m_ref": "cmdb_m2m_model_substitute",
        "sysparm_collection_related_field": "substitute",
        "sysparm_collection_key": "model",
        "api": "api",
        "sysparm_collectionID": "a9795bb0db5c7c90981b5baed39619c7"
    }
}

Has anybody encountered this problem or know how to fix this error in Workspace before ?

2 REPLIES 2

Paul Curwen
Giga Sage

Your issue is that you are trying to redirect to catalog UI Page from Agent Workspace which cannot be redirected in that way.

 

Try this:

 

var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set('sysparm_m2m_ref', 'cmdb_m2m_model_substitute');
uri.set('sysparm_stack', 'no');
uri.set('sysparm_collectionID', current.sys_id);
uri.set('sysparm_collection_key', 'model');
uri.set('sysparm_collection_related_file', 'cmdb_model');
uri.set('sysparm_collection_related_field', 'substitute');

if (typeof g_aw != "undefined") { //only do this redirect if we are on classic form
    action.setRedirectURL(uri.toString('sys_m2m_template.do'));
    gs.setReturn(current.getLink(true));
} else {
    location.replace('<YOUR_URL>');
}
***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Hi Paul,

When I tried your codes and I found that it only runs when I tick the option Client in my UI Action. It looks like the server script doesn't have g_aw only client scripts has it so it is always returns "undefined" when I'm using server script.

typeof g_aw != "undefined"