Querying Related Tables sc_req_item and sc_cat_item

kailashthiyagar
Kilo Guru

My requirement is to pass in the "Requested Item number" and "requested item name" and check whether any records exist...

Noticed that name field is present in different table sc_cat_item... I m passing in the Requested item number and name from my client script.. This is the below code i m using...

but do we have an option to do dot walking and do this validation.. i tried it but it doesnt work... could any suggest how we can do it in simplied way?

var reqDetails = new GlideRecord('sc_req_item');

  //var catItem = reqDetails.addJoinQuery('sc_cat_item');

  reqDetails.addQuery('number',g_form.getValue('request_number_2'));

  //catItem.addCondition('name', 'Hardware Exception Appeal');

  reqDetails.query();

  //create and return the array of environments

  while(reqDetails.next()){

  var catItemData=new GlideRecord('sc_cat_item');

  catItemData.addQuery('sys_id',reqDetails.cat_item);

  catItemData.query();

  while(catItemData.next()){

  //do the logic over here

  }

}

25 REPLIES 25

Yes Sourabh.. we will be implementing the glide record functionality in Script include and will use glide ajax in the client script .. So ultimately, we will need to query tables.. rit?


Yes you ill have to do all the querying stuff in the script include. Let me know if you need any help in scripting.


Yes thats correct. Just that you can dot walk multiple times in script includes. As mentioned by Abhinay, let us know if any help is required.



Kind regards,


Sourabh


Could you help me in how we can do this using dot walking for this scenario.. Just the code on the script include alone s enough


eg: you can do current.assigned_to.department.name to get the department name of the current assigned_to person on an incident form.


In the same way you can replicate your scenario:



var reqDetails = new GlideRecord('sc_req_item');  


//var catItem = reqDetails.addJoinQuery('sc_cat_item');  


reqDetails.addQuery('number',"RITM0000016");  


 


//catItem.addCondition('name', 'Hardware Exception Appeal');  


reqDetails.query();


reqDetails.next();


gs.addInfoMessage(reqDetails.cat_item.name);           // This will print the catalog item name


gs.addInfoMessage(reqDetails.cat_item.vendor.name); // this will print out the vendor name which is on the catalog item



Please mark the answer helpful or correct if you fell so.


Kind regards,


Sourabh