advanced view rules

RudhraKAM
Tera Guru

can we use both condition and check the logged in users role in the advanced view rules ?

as we cannot use the current element in the view rules 

how do we check condition (where open RITM is from software catalog ) and logged in user has itil role then go to ess view.

 

can some one help me with this 

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

If you need to check the user's role then you have to use the advanced script. In your other post I showed how to get both with an advanced script:

https://community.servicenow.com/community?id=community_question&sys_id=63545a6bdbbe6700d6a102d5ca961937

But also from your other post you mention to check against a Portal page as well. The view rules won't work if you're viewing a record using a "ticket" page because the ticket page doesn't direct pull in the "form" directly. Although, you can set the "view" it can use via the url it's pulling that from the url and then setting that view in the server script. 
Viewing a record with the "form" page is made more in line with the platform view and will execute view rules. Thus in order to use the actual "view rules" setup with portal you'll need to view the RITM using the form page or a page using the form widget.

View solution in original post

17 REPLIES 17

I am so sorry for the confusion ,, the image which shows above is the place where users RITM and request resides , and the next step is where the view thing will show up , when the user click on any ritm then it will show up 

below is the ritm  url when clicked 

https://XXXdev.service-now.com/nav_to.do?uri=%2Fsc_req_item.do%3Fsys_id%3De6cddd59dbcf6b40cebc550a4896195d%26sysparm_view%3DMy_Self-Service%26sysparm_record_target%3Dtask%26sysparm_record_row%3D1%26sysparm_record_rows%3D45%26sysparm_record_list%3Dnull%253DNULL%255Eopened_byDYNAMICjavascript%253Ags.getUserID%2528%2529%255EORref_sc_req_item.u_request_item_requested_forDYNAMICjavascript%253Ags.getUserID%2528%2529%255EORwatch_listDYNAMICjavascript%253Ags.getUserID%2528%2529%255Esys_class_name%253Dincident%255EORsys_class_name%253Dsc_req_item%255EORsys_class_name%253Du_inquiries%255EORsys_class_name%253Dsc_request%255EORDERBYDESCnumber

 

 

 

{sys_id=b4e2f599db03ab40cebc550a489619ca, view=sp, id=form, time=1547608736418, portal_id=67ebcbc913408700be045d622244b029, api=api, table=sc_req_item, request_uri=/its?id=form&table=sc_req_item&sys_id=b4e2f599db03ab40cebc550a489619ca&view=sp}b4e2f599db03ab40cebc550a489619ca67ebcbc913408700be045d622244b029

 

 

This is the log for the isportal ,, how will it check for if it is opened from portal or not ?

below is what my code looks like ,,as I changed the value of closed incomplete to 4 as it is the back end value and its working if i changed it ( just by giving that condition)

Do i need to change any thing to get the URL and do i need to change any thing to get the catalog value?

 

(function overrideView(view, is_list) {
//get URL details
var url = gs.action.getGlideURI().getMap();

// parse url for information needed
var recSysId = url.get('sys_id');
var isPortal = url.get('portal_id');

// RITM
var ritm = new GlideRecord('sc_req_item');
var state;
var catType;
if(ritm.get(recSysId)){
state = ritm.getDisplayValue('state');
catType = ritm.cat_item.sc_catalogs.getDisplayValue();
}
if( !gs.hasRole('itil') && !isPortal ){
view = 'ess';
}
if( !gs.hasRole('itil') && isPortal ){
if(state != '4' && catType.indexOf('Software Catalog') > -1){
view = 'sp';
}
else if(state == '4' && catType.indexOf('Software Catalog') > -1){
view = 'sp_cancelled';
}
else if(isPortal && catType.indexOf('Software Catalog') > -1){
view = 'ess';
}

if( gs.hasRole('itil') && !isPortal ){
view = 'default';
}


if( gs.hasRole('itil') && isPortal ){

if(state != '4' && catType.indexOf('Software Catalog') > -1){
view = 'sp';
}
else if(state == '4' && catType.indexOf('Software Catalog') > -1){
view = 'sp_cancelled';
}
}
answer = view;
} })(view, is_list);

Yes, my turn to apologize. I forgot to answer your previous questions. 
catType = ritm.cat_item.sc_catalogs.getDisplayValue();
That statement grabs the catalogs the item belong to.  - "cat_item" is the reference field on the RITM that references the actual item. And "catalogs" is the field (list collector) on the actual item that holds the list of catalogs. I used getDisplayValue because otherwise it would give me a list of sys_ids. 

From there "catType.indexOf('Software Catalog') > -1" will check to see if "Software Catalog" is in that list. Here I used "Software Catalog" because in your post of requirements you stated " (where open RITM is from software catalog )".  However, the name might actually be just Software. I don't know as it's not my environment. So, if "Software Catalog" isn't the name of your software catalog, yes you will need to change that to the actual name. Or you can grab sys_ids instead and use sys_id

For this statement: "var isPortal = url.get('portal_id');"
When navigating to the portal on a page using the form widget the gs.action.getGlideURI() will catpure a url that contains "portal_id" as one of the parameters. Hence this statement: "url.get('portal_id')". A portal_id normally doesn't appear in the platform UI. Some of the other parameters might. That is why I used it. I didn't use "view" as sometimes a "view" isn't tagged on to the end of the url thus it would be blank and not show up in the parameter search.

 

thanks for the detailed explanation and your time , i really appreciate it.