User Criteria logic/ script

sas1
Kilo Expert

In our instance, we have a custom field (reference to a custom table called Org). This field is on the Department table and is dot-walked to from almost all our ITSM processes. 

We need to build a user criteria (Available For) based on this this custom field (Org). This user criteria will be used in the portal Announcements.  

We added the Org field to the User Criteria form but we are not able to make it work. I am sure somewhere in some script we have to update the logic as to where it should be looking to validate if the user passes this Org criteria or not. 

Where exactly should we be looking to add this logic of the newly added User Criteria field?  Thanks.

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

I don't believe that you could update the internal ServiceNow logic to include that field directly. What you could do is use the advanced option in the user criteria and then script your check. 

You would want to write a function that returns a true or false based on the conditions that you want. 

In order to lookup the user, you would use the "magic" variable user_id.

So, something like this: 

checkCondition();

function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(user_id);

if(user.department.<your_custom_field> == 'whatevervalue') {
return true;
}
return false;


}

If the function returns true, the user will have access, otherwise they will not. 

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

3 REPLIES 3

Michael Jones -
Giga Sage

I don't believe that you could update the internal ServiceNow logic to include that field directly. What you could do is use the advanced option in the user criteria and then script your check. 

You would want to write a function that returns a true or false based on the conditions that you want. 

In order to lookup the user, you would use the "magic" variable user_id.

So, something like this: 

checkCondition();

function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(user_id);

if(user.department.<your_custom_field> == 'whatevervalue') {
return true;
}
return false;


}

If the function returns true, the user will have access, otherwise they will not. 

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

For people not getting consistent results when testing try clearing the system cache (by searching cache.do in the application navigator) after updating the user records...took me a while to figure out why it was sometimes working and sometimes not.

 

Hello Winston,

Good Day! Thanks a lot it helps 🙂

Thanks,

Priyanka R