- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 07:33 AM - edited ‎11-06-2024 07:36 AM
Hi friends! I am currently stuck and need someone more learned to explain why my code doesn't work.
Here's the case: I have a MRVS on a catalog item that has a Lookup Select box (serial_number on
var getPhoneNum = Class.create();
getPhoneNum.prototype = Object.extendsObject(AbstractAjaxProcessor, {
numDetails: function() {
var dvc = this.getParameter('sysparm_device');
var tab = new GlideRecord("cmdb_ci_handheld_computing");
tab.addQuery("sys_id", dvc);
tab.query();
if (tab.next()) {
var nbr = tab.getDisplayValue('phone_number');
}
return nbr;
},
type: 'getPhoneNum'
});
and here is the Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc = new GlideAjax("getPhoneNum");
abc.addParam("sysparm_name", 'numDetails');
abc.addParam("sysparm_device", newValue);
abc.getXML(getResult);
function getResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("phone_number", answer);
alert(answer);
}
}
This is returning null and I am losing my mind trying to figure this out. Help, please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 09:16 AM - edited ‎11-06-2024 09:22 AM
Hey Brad!
Thanks for your reply! Logs from the script that you updated are showing that I am getting the correct information, a serial number. I think where I am confused is how to query for the phone_number field once I have the seriaul. Currently the alert shows "false" and puts "false" where I want the phone number to be, so maybe the gliderecord query isn't right?
I have a variable set holding the MRVS and the catalog client script. The variable set is added on the catalog item. Is that correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 09:38 AM
If the log for dvc = a serial number, you either need to change the variable Lookup value field to sys_id, which doesn't affect the choice labels, or change the addQuery to ('serial_number', dvc);. Either should result in the 'record found' log, and returning the value of the phone_number field from that record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 08:18 AM
Hi Andy,
You can add some temporary logs to the Script Include to confirm the value passed in from the client, and if any records are retrieved. It's also best to always return something from a SI, to avoid errors and uncertainty if the script is even running. Here's what that looks like:
var getPhoneNum = Class.create();
getPhoneNum.prototype = Object.extendsObject(AbstractAjaxProcessor, {
numDetails: function() {
var nbr = 'false';
var dvc = this.getParameter('sysparm_device');
gs.info('AM SI dvc = ' + dvc);
var tab = new GlideRecord("cmdb_ci_handheld_computing");
tab.addQuery("sys_id", dvc);
tab.query();
if (tab.next()) {
gs.info('AM SI record found ' + tab.display_name);
nbr = tab.getDisplayValue('phone_number');
}
return nbr;
},
type: 'getPhoneNum'
});
Is the Lookup value field = sys_id or something else? Are both variables, and the client script in the MRVS? If the system logs (filter on message starts with AM SI) show the expected record is returned, try nbr = tab.getValue('phone_number'); If you are not seeing any logs, confirm that there are no other Script Includes with this name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 09:16 AM - edited ‎11-06-2024 09:22 AM
Hey Brad!
Thanks for your reply! Logs from the script that you updated are showing that I am getting the correct information, a serial number. I think where I am confused is how to query for the phone_number field once I have the seriaul. Currently the alert shows "false" and puts "false" where I want the phone number to be, so maybe the gliderecord query isn't right?
I have a variable set holding the MRVS and the catalog client script. The variable set is added on the catalog item. Is that correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 09:38 AM
If the log for dvc = a serial number, you either need to change the variable Lookup value field to sys_id, which doesn't affect the choice labels, or change the addQuery to ('serial_number', dvc);. Either should result in the 'record found' log, and returning the value of the phone_number field from that record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 08:20 AM
I have implemented the same requirement in my PDI. Pasting the code below. Before that click on client callable in script include//
Script include
var MRVS_auto = Class.create();
MRVS_auto.prototype = Object.extendsObject(AbstractAjaxProcessor, {
numDetails: function() {
var dvc = this.getParameter('sysparm_caller');
var tab = new GlideRecord("incident");
tab.addQuery("caller_id", dvc);
tab.query();
if (tab.next()) {
var nbr = tab.getDisplayValue('number');
gs.info("Waseem1"+nbr);
}
return nbr;
},
type: 'MRVS_auto'
});
Catalog client script on variable set
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc = new GlideAjax("MRVS_auto");
abc.addParam("sysparm_name", 'numDetails');
abc.addParam("sysparm_caller", newValue);
abc.getXML(getResult);
function getResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("incident_no", answer.toString());
alert(answer);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Waseem Mohammed.