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

Abhinay Erra
Giga Sage

I will recommend to use GlideAjax.


GlideAjax - ServiceNow Wiki


sourabhd87
Tera Contributor

Can you please let me know the need of this script? I   am unable to identify your aim.



Kind regards,


Sourabh


Hi Sourabh,


My requirement is, if the user enters in the request no(the one which he has already raised), we will be validating whether its a valid request number by querying against the requested item table


So best bet would be to use GlideAjax. As gliderecord use in client scripts not recommended.





Kind regards,


Sourabh