Assistance Required with Portal Routing Logic Based on User Company

Gulfam
Giga Guru

Hi Expert

I have a requirement related to portal routing that I need some help with. Here's the scenario:

  • If a user belongs to company "ABC," they should be routed to the Service Portal (SP).
  • If a user belongs to company "XYZ," they should be routed to the Customer Service Management portal (CSM).
  • After logging out, the user should be redirected to the common login page (SP landing page).

I’ve created a new Script Include that inherits the SPEntryPage Script Include. In the initialize function, I added the following code:

 

 
var userId = gs.getUserID();
var userRec = new GlideRecord('sys_user'); userRec.addEncodedQuery('sys_class_name=customer_contact^company.nameINXYZ^sys_id=' + userId); userRec.query();
if (userRec.next()) {
this.portal = "/csm/";
} else {
this.portal = "/sp/";
}
 

When I impersonate a user from company "XYZ," the CSM portal is displayed as expected. However, when I log in using my credentials (from company "XYZ"), it always redirects me to the Service Portal (SP) instead of the CSM portal.

Could you please assist me in resolving this? I suspect there may be an issue with how the user's company is being checked or how the logic is being applied during login.

Looking forward to your guidance on this.

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@Gulfam 

the 1st case which worked you are impersonating a user from company but in 2nd case you are impersonating as contact user of some account

So try to update as this

var userRec = new GlideRecord('sys_user');
userRec.addEncodedQuery('company.nameINXYZ^sys_id=' + userId);
userRec.query();

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

Hi Ankur, 

I have made the changes, but still getting the same error. 

Dimah_0-1734965986728.png


But when i impersonate with the same user 

 

Dimah_1-1734966075239.png

 



@Gulfam 

did you add logs and see ?

for 2nd case you are impersonating user from customer_contact table?

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

I am using sys_user table