How to check if a record is existing in a custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 11:25 PM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 11:49 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 03:57 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:09 AM
Hi Saurav, can we do glide record in the client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:31 AM
Yes, excluding a few scenarios we can.
Thanks.
Please mark the answer correct/helpful based on impact.