Where to add action.setRedirectedURL(current) in client callable UI action.

Obito
Tera Expert

Hi all, My client callable UI action is being redirected to other page. I used action.setRedirectURL(current) but it is still being redirected to other page. Please refer below code.

 

function doIt() {
    if (confirm("Are you sure")) {
        //alert("You clicked yes");
        gsftSubmit(null, g_form.getFormElement(), 'populate');
    }
}

if (typeof window == 'undefined')
    updateRecord();

function updateRecord() {
    var inputs = {};
    inputs['table_name'] = 'incident';
    inputs['incident'] = current;
    // Start Asynchronously: Uncomment to run in background.
    sn_fd.FlowAPI.startFlow('global.Test Inc', inputs);
    action.setRedirectURL("https://dev223110.service-now.com/incident.do?sys_id=57af7aec73d423002728660c4cf6a71c");
    // Execute Synchronously: Run in foreground.
    //sn_fd.FlowAPI.executeFlow('global.[internal name of flow]', inputs);
}

 

 

5 REPLIES 5

jcmings
Mega Sage

I might be mistaken, but I believe action is reserved for server-side code only. Try using window.open(url) and set your variable url equal to '/incident.do?sys_id=....' (basically everything after instance-name.com). 

 

(I am assuming you have hard-coded your redirect URL for testing purposes in the script you shared above.)

Chaitanya ILCR
Kilo Patron

Hi @Obito ,

action.setRedirectURL(current); statement should work
you can also put the URL but the only path required. you don't have to give entire URL inside the method.
action.setRedirectURL('incident.do?sys_id='+addTheSysidOfTheRecord);
 
Regards,
Chaitanya

Robbie
Kilo Patron
Kilo Patron

Hi @Obito,

 

When passing the URL within the method, you do not need to reference the instance name and domain. simply pass the paramter or string of "/incident.do?sys_id=57af7aec73d423002728660c4cf6a71c".

 

I would however recommend against hard coding the sys_id. This should be declared as a varable and using dynamically.

 

Eg: action.setRedirectURL("/incident.do?sys_id=" + varriableNameOfsysID);

 

If you haven't already seen this SN Docs article on the implementation of a UI action (and importantly how a UI action uses both a client side and server side code) - check the following link:

https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/script/useful-scripts/reference/usi...

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.





Thanks, Robbie

Anand Kumar P
Giga Patron
Giga Patron

Hi @Obito ,

 

Whatever you written after if(typeof window==“ undefined”) is serverside if you want server side use below one 

 

action.setRedirectURL("/incident.do?sys_id=“+ sys_id variable name);

 

if you want in client side use below 

var url = '"https://dev223110.service-now.com/incident.do?sys_id=57af7aec73d423002728660c4cf6a71c";

top.window.open= url;

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand