- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2021 04:01 PM
Hi All,
I'm working on a catalog item that includes 2 variables: Computer (references [cmdb_ci_computer] table) & Stockroom (references [alm_stockroom] table). The requirement is to automatically populate the Stockroom variable based on the CI selected in the Computer variable. This requires 2 levels of dot-walking from the CI.Asset.Stockroom and I believe the best approach is to create a Script Includes + Catalog Client Script. I created both scripts below, however the functionality isn't working. Any guidance on what's missing would be much appreciated.
Computer CI Record:
Hardware Asset Record:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2021 02:08 PM
Couple things:
1. this should solve your issue - change "return gr.asset.stockroom.getDisplayValue();" to "return gr.asset.stockroom.toString();". You need a sys_id as your variable is a reference field, correct?
2. Just to make things easier, change "ga.getXML(callBackMethod);" in the Client Script to "ga.getXMLAnswer(callBackMethod);". That way your "response" parameter contains the result without having to pick the answer out of the XML tree.
Just try #1 first to confirm and #2 if you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2021 07:26 AM
Try keeping logs and verify values at all places.
var ComputerUtils = Class.create();
ComputerUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIDetails: function(){
var id = this.getParameter('sysparm_computer');
gs.info("CI IS"+id);
var gr = new GlideRecord('cmdb_ci_computer');
gr.get(id);
gs.info("Stockroom"+gr.asset.stockroom.getDisplayValue());
return gr.asset.stockroom.getDisplayValue();
},
type: 'ComputerUtils'
});
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage(g_form.getValue('computer'));
var ga = new GlideAjax('ComputerUtils');
ga.addParam('sysparm_name', 'getCIDetails');
ga.addParam('sysparm_computer',g_form.getValue('computer'));
ga.getXML(callBackMethod);
}
function callBackMethod(response) {
g_form.addInfoMessage("Hello");
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer != ''){
g_form.setValue('stockroom', answer);
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2021 01:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2021 02:08 PM
Couple things:
1. this should solve your issue - change "return gr.asset.stockroom.getDisplayValue();" to "return gr.asset.stockroom.toString();". You need a sys_id as your variable is a reference field, correct?
2. Just to make things easier, change "ga.getXML(callBackMethod);" in the Client Script to "ga.getXMLAnswer(callBackMethod);". That way your "response" parameter contains the result without having to pick the answer out of the XML tree.
Just try #1 first to confirm and #2 if you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2021 02:42 PM
Hi