- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 10:53 PM
I would like to automatically change Views between Portal and internal platform using View Rule. The condition is like below:
If
- Short description is "1"
AND
- Accessed from Service Portal
Then
Apply "u_1_portal" View
Else if
- Short description is "1"
AND
- Accessed from internal platform (NOT portal)
Then
Apply "u_1" View
I created a View Rule as per the advice in the following thread, but it doesn't work properly.
Could someone please modify the script to ​make it work?
https://community.servicenow.com/community?id=community_question&sys_id=63545a6bdbbe6700d6a102d5ca961937
(function overrideView(view, is_list) {
//get URL details
var url = gs.action.getGlideURI().getMap();
//Determine if in portal view
var isPortal = url.get('portal_id');
var gr = new GlideRecord('u_target_table');
if(gr.short_description == '1' && isPortal){
answer = 'u_1_portal';
}
if(gr.short_description == '1' && !isPortal ){
answer = 'u_1';
}
})(view, is_list);
Best Regards,
Aki
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:42 AM
Hi Aki,
Try the below code. Its working for me.
(function overrideView(view, is_list) {
//get URL details
var url = gs.action.getGlideURI().getMap();
//Determine if in portal view
var isPortal = url.get('id');
var sys_id = url.get('sys_id');
if(sys_id){
var gr = new GlideRecord('u_target_table');
if(gr.get(sys_id)){
if(gr.short_description == '1' && isPortal){
answer = 'u_1_portal';
}
if(gr.short_description == '1' && !isPortal ){
answer = 'u_1';
}
}
}else{
answer=null;
}
})(view, is_list);
Please mark it as helpful/correct If my answer is helpful in any way,
Best regards,
Thameem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 11:46 PM
Hello,
How will you do it without the sysid:-
Try this:-
(function overrideView(view, is_list) {
//get URL details
var url = gs.action.getGlideURI().getMap();
//Determine if in portal view
var isPortal = url.get('portal_id');
var recSysId = url.get('sys_id');
var gr = new GlideRecord('u_target_table');
if(gr.get(recSysId)){
if(gr.short_description == '1' && isPortal){
answer = 'u_1_portal';
}
if(gr.short_description == '1' && !isPortal ){
answer = 'u_1';
}
}
})(view, is_list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 12:47 AM
Hi Saurav,
Thank you for the script, but it doesn't work and views are not set when loading the target table form...
Could you please check where the wrong part is?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 01:42 AM
Hi Aki,
Try the below code. Its working for me.
(function overrideView(view, is_list) {
//get URL details
var url = gs.action.getGlideURI().getMap();
//Determine if in portal view
var isPortal = url.get('id');
var sys_id = url.get('sys_id');
if(sys_id){
var gr = new GlideRecord('u_target_table');
if(gr.get(sys_id)){
if(gr.short_description == '1' && isPortal){
answer = 'u_1_portal';
}
if(gr.short_description == '1' && !isPortal ){
answer = 'u_1';
}
}
}else{
answer=null;
}
})(view, is_list);
Please mark it as helpful/correct If my answer is helpful in any way,
Best regards,
Thameem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 02:34 AM
Hi Thameem,
Thank you for your script!
It worked for Service Portal ("u_1_portal" View), but NOT for internal platform ("u_1" View)...
Could you check if there is any problem with the script?
*The 'u_target_table' is the custom table that extends Case [sn_customerservice_case] table.