- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 07:54 PM
Hello,
I'm attempting to create a user criteria based on value of a custom field we have on our customer_account table. If the field (u_remote_access_active) on the customer account is checked (true), then the user criteria should evaluate as true.
I'm not confident I have all methods named correctly, but here is the code and my general direction so far:
checkCondition();
function checkCondition() {
var customer_account = gs.getUser().getCompanyRecord();
if(customer_account.u_remote_access_active == true) {
return true;
}
return false;
}
Any help would be appreciated, thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:02 PM
Thanks Saurav11. I couldn't quite get it to work using this method, but I ended up finding another solution using addEncodedQuery that thankfully did the trick. So this ended up being what worked for me:
var accounts = new GlideRecord("customer_account");
accounts.addEncodedQuery("customer=true^u_remote_access_active=true");
accounts.query();
if (accounts.next()) {
answer = true;
} else {
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 08:11 PM
Hello
You will have to use glide to make it work.Now assuming that your custom_account table has a reference field for user and also the temote active field use the below:-
checkCondition();
function checkCondition(){
var gr= new GlideRecord('customer_account')
gr.addQuery('replaceuserfieldnameoncustoneraccount',gs.getUserId());
gr.query();
if(gr.next())
{
if(gr.u_remote_access_active == true) {
return true;
}
return false;
}
}
Please mark my answer as correct based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:02 PM
Thanks Saurav11. I couldn't quite get it to work using this method, but I ended up finding another solution using addEncodedQuery that thankfully did the trick. So this ended up being what worked for me:
var accounts = new GlideRecord("customer_account");
accounts.addEncodedQuery("customer=true^u_remote_access_active=true");
accounts.query();
if (accounts.next()) {
answer = true;
} else {
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 01:47 PM
I know this is already solved but I wanted to reply in case this helps others. The reason the encoded query worked for you while your original script didn't, is because your script with encoded query did not use gs.getUser(). You need to use the predefined variable: user_id instead of using gs.getUser()