UI Action redirect - portal vs. back-end

davilu
Mega Sage

Our team is creating an UI Action on a form and would like it to redirect to another page on the portal, but redirect to another form on the back-end.  Right now when a user submits a new user on sys_user in the back-end, the button will redirect them directly to the HR Profile form as a next step.  When a user does this same action in the portal, we would like to redirect them to another portal page for the HR Profile form.  Is there a way to script this?  

current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile)
  action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
3 REPLIES 3

chrisperry
Giga Sage

Could you please provide the full script for your UI action? Is the button already displaying properly on the portal?

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Hi, that actually is the full script for the UI Action.  Right now in the back-end it looks like this:

find_real_file.png

When clicked, it takes the user here:

find_real_file.png

 

All of that is working as expected in the back-end, but we want to do something similar in the portal.  In the above script, is there a way to say if portal then redirect here else redirect there?

something like this...?

current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile){
  if(portal){
    //redirect to this url
  } else {
  action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
  }
}

Got it -- I think the below should work:

current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile){
  var portal = gs.action.getGlideURI().toString().startsWith('api/now/sp'); //true if service portal, false if native view
  if(portal){
    //redirect to this url
  } else {
  action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
  }
}

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry