The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Need to hide a service catalog item if they have any records in a certain table?

ksmithdev
Mega Expert

Hello!

 

Thanks for your time. I am trying to write a onLoad client script that checks a table called u_user_devices, and if it pulls even a single record tied to that user, the catalog item must become hidden on load. If no records are found, they are able to see it, and complete the request. For some reason, I can only ever get it to hide from everyone nomatter what, or be completely visible. I have what I wrote so far below, but I am wondering if anyone can help me. I do not need to pull a specific record from the u_user_devices table, it is just that if they have any records there, they are not allowed to order this item.

 

function onLoad()

{

  var userID = g_user.userName;

  var gr = new GlideRecord('u_user_device');

  gr.addQuery('u_user_name', userID);

  gr.query();

  alert("User : " + userID);

  alert("Username in Table : " + gr.u_user_name);

  if (gr.u_user_name != '') {

  if (gr.hasNext())

  {

  alert("Sys ID of Device User : " + gr.sys_id);

  g_form.setDisplay('lbl_service_req_form',false);

  g_form.setDisplay('shipping_info',false);

  g_form.setDisplay('service_plan',false);

  g_form.setDisplay('user_information',false);

  g_form.setDisplay('carrier_information',false);

  g_form.setDisplay('policy_acceptance',false);

  g_form.setReadonly('not_auth',true);

  x = gel('cart');

  x.style.display = 'none';

  console.log("Hidden");

  }

  if (!gr.next) // Has no device

  {

  g_form.setDisplay('not_auth',false);

  console.log("You should be able to see form.");

  }

 

 

  }

}

 

Thanks for your help!

6 REPLIES 6

If that worked for you, please mark the appropriate response as being the correct answer so others will see that a valid solution was found.   Thanks.


Jim Coyne
Kilo Patron

Just curious if the entitlement script worked out for you?