Querying Related Tables sc_req_item and sc_cat_item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 08:59 AM
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
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:10 PM
Here is your updated script include. Also as mentioned earlier, change the call back function in your client script as well.
var EUTSCatalogRITMValidation = Class.create();
EUTSCatalogRITMValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateRequestNumber: function(){
var answer=[];
var reqNo = this.getParameter('sysparm_req_number');
var reqDetails = new GlideRecord('sc_req_item');
reqDetails.addQuery('number',reqNo);
reqDetails.query();
//create and return the array of environments
while(reqDetails.next()){
answer.push(reqDetails.cat_item.name);
}
return answer.toString();
},
type: 'EUTSCatalogRITMValidation'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:02 PM
In your client script, the call back function should be this
function validateReqNo(response) {
var answer=response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:11 PM
Hi Abhinay.. We can do either way also... but as an FYI, i have tried your apprpoach but it give undefined only

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:12 PM
use the updated script include form my previous comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:26 PM
HI Kailash,
I tried following on my developer instance:
======================Script Include=======================
var EUTSCatalogRITMValidation = Class.create();
EUTSCatalogRITMValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateRequestNumber: function(){
var answer=[];
var reqNo = this.getParameter('sysparm_req_number');
var reqDetails = new GlideRecord('sc_req_item');
reqDetails.addQuery('number',reqNo);
reqDetails.query();
//create and return the array of environments
while(reqDetails.next()){
answer.push(reqDetails.cat_item.name);
}
return answer.toString();
},
type: 'EUTSCatalogRITMValidation'
});
===========================================================================
++++++++++++++++++ClientScript++++++++++++++++++++++++++++
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('EUTSCatalogRITMValidation');
var reqNo="RITM0000016";
ga.addParam('sysparm_name','validateRequestNumber');
ga.addParam('sysparm_req_number',reqNo);
ga.getXML(validateReqNo);
function validateReqNo(response) {
var answer=response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It works for me. Try putting a specific RITM number in the above reqNo.
Make sure you have the checkbox: Client Callable marked as true.
Let me know the result.
Kind regards,
Sourabh