The CreatorCon Call for Content is officially open! Get started here.

How to access a table values on a Catalog Client Script?

Sagar Manocha
Tera Contributor

Hi All,

I am modifying an OOB Record Producer 'Create Incident' in which end user can create an incident through Portal. In this, I'm trying to check if the current user is a VIP User or not. If the user is a VIP user, then the Urgency variable present in the Record Producer should be auto-populated with a certain value. 

Here is the code that I am using: 

function onLoad() {
//Type appropriate comment here, and begin script below
var currentUser=new GlideRecord('sys_user');
currentUser.addQuery('user_name',g_user.userID);
currentUser.query();
var vipStatus;
var vvipStatus;
if(currentUser.hasNext()){
g_form.addInfoMessage("inside if");
vipStatus=currentUser.vip;
vvipStatus=currentUser.u_vvip;
}
if(vipStatus=="true"){
g_form.setValue('urgency',7,'VIP');
g_form.setReadOnly('urgency',true);
}
if(vvipStatus=="true"){
g_form.setValue('urgency',7,'VIP');
g_form.setReadOnly('urgency',true);
}
}

5 REPLIES 5

Naveen Sagar S1
Mega Guru

Hi,

Your code looks fine, Is there any issue you are facing.

Also try to replace the GlideRecord with GlideAjax to avoid performance issues.

Sagar Manocha
Tera Contributor

Naveen,

First of all, after quering the table, i am not able to fetch any record from the user table. I've thoroughly checked all the field names, still not able to find the reason of this script not working. In order not to user GlideRecord, I've user getReference method, still it is not working. Below is the code that i am using now.

function onLoad() {
//Type appropriate comment here, and begin script below
g_form.addInfoMessage(g_form.getValue('caller_id'));
var req=g_form.getReference('caller_id', somefun);
var status;
function somefun(req){
status=req.getValue('vip');
}
var status1=req.vip;
g_form.addInfoMessage("status "+status1);
}

Hi,

In your first code using GlideRecord,

replace the user_name with sys_id in the add query statement.

 

I think you want an onChange script against the caller_id variable.  Your issue may just be that the field isn't populated when your onLoad script runs.

 

Also, when you're using a callback function, you wouldn't set it to a variable.

So instead of...

var req=g_form.getReference('caller_id', somefun);

Just..

g_form.getReference('caller_id', someFun);

 

and then see if this displays the correct value...

 

function someFun(caller) {

   g_form.addInfoMessage(caller.vip);

}