Why Form UI Action SetRedirectURL not working in PORTAL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:59 AM - edited 03-24-2024 07:45 PM
Hi Team,
WE have Child Financial button on record, when we click on it it has to copy all Parent record values and create new record.
var gr = new GlideRecord('u_financial');
gr.initialize();
gr.description=current.description;
gr.insert();
action.setRedirectURL(gr);
UI action code working properly at Desktop side created new record & redirected to new record,
But not working at portal when we click on Button just getting message ' Record updated' , not redirecting to newly created Record. what would be the reason please.
what would be the issue, kindly let me know. I tried in my personal PDI, same problem coming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:39 PM
action.setRedirectURL doesn't work in portal side; there is a KB for this
action.setRedirectURL(url) does not work in UI Action for Service Portal
check this link for workaround
A work-around for setRedirectURL() in the Portal
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:55 PM
Hi @Supriya25 ,
Please use location.href ="your redirection url" in client controller in that widget.
If my response helped please mark it correct.
Thanks and Regards,
Allu Gopal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 01:05 AM
Hi @Supriya25
At least for Jakarta action.setRedirectURL(url) doesn't work in the Portal.
Here is my workaround:
It adds extra function call before action.setRedirectURL(url) + a code to get data in portal form.
new UserPreferences().setUrlToOpen(url);
action.setRedirectURL(url);
Line 90 of Form widget - add additional function call after last then to get
loadForm($scope.data.table, sysID).then(constructResponseHandler(response)) .then(redirectFix);
function redirectFix(){
ctrl.data.action = "checkRedirect"
ctrl.server.update().then(function(response){
if(response.forceRedirectTo){
$window.location = (response.forceRedirectTo);
} else {
ctrl.data.action = ""
}
})
}
Server side action is:
if(input.action === "checkRedirect"){
var urlToOpen = new UserPreferences().getUrlToOpen();
if(urlToOpen){
data.forceRedirectTo = urlToOpen;
}
return;
}
I save temp values to user preferences, but in your case in could be better to place temp data to user session.
var UserPreferences = Class.create();
UserPreferences.prototype = {
initialize: function() {
this.urlPref = "fix.redirectAction.url";
this.urlPrefTimer = "fix.redirectAction.url.timer";
},
/*
save url. use to fix action.setRedirect for the Portal
*/
setUrlToOpen:function(url){
gs.getUser().savePreference(this.urlPref, url);
gs.getUser().savePreference(this.urlPrefTimer, new Date().getTime());
},
/*
When to url or it is older then 1 minute - returns empty string
*/
getUrlToOpen: function(){
var url = "";
var old = gs.getUser().getPreference(this.urlPrefTimer);
var outDated = (new Date().getTime() - old ) /1000 > 60;
if(!outDated) {
url = gs.getUser().getPreference(this.urlPref);
}
return url;
},
type: 'UserPreferences'
};
credit: @Igor Kozlov
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....