User criteria script not working as expected

M_iA
Kilo Sage

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

1 ACCEPTED SOLUTION

@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.

 

View solution in original post

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

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.

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?

@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.

 

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.