How to check if a record is existing in a custom table.

Indira8
Kilo Sage

Hi All, 

We have a custom table where there are 3 reference fields dep, owner and escalation which refer to the user table. 
Requirement is that whenever logged in user tries to access the catalog item , if user is a part of any of these then certain variables should be visible otherwise no.
Could you help me with the code for querying the custom table and checking if the logged in user record is present in any of the fields.

Thank you 

15 REPLIES 15

Saurav11
Kilo Patron
Kilo Patron

Hello,

Write a onload catalog client script as below:-

 

function onLoad() {
//Type appropriate comment here, and begin script below
var sys_id=g_user.userID;
var gr = new GlideRecord('custom_table');
gr.addQuery('dep',sys_id);
gr.addQuery('owner',sys_id);
gr.addQuery('escalation',sys_id);
gr.query();
if(gr.next())

{
g_form.setVisible('varibalename',false);
}
else
{
g_form.setVisible('varibalename',false);
}
}

 

Please mark the answer correct/helpful based on impact.

Helllo,

Did you get a chance the check the below script:-

function onLoad() {
//Type appropriate comment here, and begin script below
var sys_id=g_user.userID;
var gr = new GlideRecord('custom_table');
gr.addQuery('dep',sys_id);
gr.addOrCondition('owner',sys_id);
gr.addOrCondition('escalation',sys_id);
gr.query();
if(gr.next())

{
g_form.setVisible('varibalename',true);
}
else
{
g_form.setVisible('varibalename',false);
}
}

 

Please mark the answer correct/helpful based on impact.

 

Hi Saurav, can we do glide record in the client script 

Yes, excluding a few scenarios we can.

Thanks.