Need to create user criteria based on custom field on account table

J McMillan
Tera Expert

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.

1 ACCEPTED SOLUTION

J McMillan
Tera Expert

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;
}

 

View solution in original post

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

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 

 

J McMillan
Tera Expert

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;
}

 

Aaron Stacken
Tera Contributor

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()