Why Form UI Action SetRedirectURL not working in PORTAL

Supriya25
Tera Guru

Hi Team,

 

Supriya25_0-1711306348025.png

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.

Supriya25_1-1711306778149.png

 


what would be the issue, kindly let me know. I tried in my personal PDI, same problem coming.


 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Supriya25 

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.

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

Gopal Allu
Tera Expert

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.

Sohail Khilji
Kilo Patron
Kilo Patron

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....

LinkedIn - Lets Connect