
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 05:02 AM - edited 05-07-2024 05:04 AM
I am trying to create a new user criteria script that looks at a custom field on the users company record to validate whether they can see the categories on the service portal or not. However, the script isnt working as expected.
Script:
gs.cacheflush("criteria_cache");
var userGR = new GlideRecord('customer_contact');
userGR.get(user_id);
if (userGR.company.u_portal_profile == 2 || userGR.company.u_portal_profile == 3) {
answer = true;
} else {
answer = false;
}
Expected outcome is that a user with a portal profile of 2 OR 3 would be able to see it.
However, they cannot view it.
Any help would be greatly appreciated
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 08:14 AM
@M_iA, purpose of
gs.cacheflush(“criteria_cache”); is to avoid logging out and logging back in to avoid changes. Seems, by the time the cache is cleared the script is being executed. You can try adding timer, if needed for a check to avoid script execution immediately after cacheflush.
In case you got it working you can avoid but if eager try out above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 05:09 AM
Hi,
Script seems fine. Can you add values in 2 and 3 in quotes. Additionally, are you sure the values you comparing are correct? You can add logs for a check to see the values for u_portal_profile.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 07:44 AM
Thanks @Jaspal Singh ,
I have add the quotes but was still not working as expected. I then went ahead and checked the logs and found the issue.
It appears that the issue is: gs.cacheflush("criteria_cache");
I have commented this out and it now runs as expected! Any ideas why this might be happening?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 08:14 AM
@M_iA, purpose of
gs.cacheflush(“criteria_cache”); is to avoid logging out and logging back in to avoid changes. Seems, by the time the cache is cleared the script is being executed. You can try adding timer, if needed for a check to avoid script execution immediately after cacheflush.
In case you got it working you can avoid but if eager try out above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 12:26 PM - edited 05-07-2024 12:26 PM
Cache flush is probably queuing a job to flush that users cache, which is completing after the rest of the script is running. I ran into an issue with this recently, there are some system properties that are supposed to tell the system to ignore the cache and re-run the criteria but they don't seem to be working anymore.