- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 08:55 PM
Hello Experts,
I have a requirement to display an alert message with table field values, on load of a catalog item.
Scenario -
1. Table A (device_asset) contains fields Asset (asset), Assigned To (assigned_to), End Date (end_date) and Description (asset_description)
2. Catalog items has variable Requested For
3. If Assigned To matches with Requested For then alert message to display as 'Requestor has and existing Asset {asset_description}, with the end date as {end_date}
I created a Script Include to fetch the values from Table A (which works fine) and a Catalog Client Script to return the alert message (which isnt working)
Catalog Client Script -
Script Include (Client Callable) -
Could you please let me know what i am doing wrong to display the field values in the alert message.
Thanks and Regards,
Somujit
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 10:46 PM - edited 08-17-2023 10:55 PM
Hi @Somujit1,
I spotted an issue with the syntax you have used for the getXMLAnswer method. Also, it might be a good idea to stick to the stringify() and parse() methods of JSON to deal with the data that is being passed from server to client.
I have rewritten the scripts in a slightly different manner where I have taken the liberty of changing the variable names and function names to make them more pertinent to what they're being used for.
/* Catalog Client Script */
function onLoad() {
var requestedFor = g_form.getValue('requested_for');
var ga_asset = new GlideAjax('GetAssetAssigneeDetails');
ga_asset.addParam('sysparm_name', 'RetrieveAssetDetails');
ga_asset.addParam('sysparm_req_for', requestedFor);
ga_asset.getXMLAnswer(assetResponse);
function assetResponse(answer) {
//var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var returneddata = JSON.parse(answer);
alert("Requestor has and existing Asset" + returneddata.assetDesc + ", with the end date as " + returneddata.endDate);
return false;
}
}
}
/* Script Include */
var GetAssetAssigneeDetails = Class.create();
GetAssetAssigneeDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
RetrieveAssetDetails: function () {
var reqUsr = this.getParameter('sysparm_req_for');
var gr_asset = new GlideRecord('device_asset');
gr_asset.addQuery('assigned_to', reqUsr);
gr_asset.setLimit(1);
gr_asset.query();
if (gr_asset.next()) {
var results = {
"endDate": gr_asset.getValue('end_date'),
"assetDesc": gr_asset.getValue('asset_description')
};
return JSON.stringify(results);
}
return false;
},
type: 'GetAssetAssigneeDetails'
});
Note: I have not tested out the code. Consider debugging both scripts if you come across any issues.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 10:46 PM - edited 08-17-2023 10:55 PM
Hi @Somujit1,
I spotted an issue with the syntax you have used for the getXMLAnswer method. Also, it might be a good idea to stick to the stringify() and parse() methods of JSON to deal with the data that is being passed from server to client.
I have rewritten the scripts in a slightly different manner where I have taken the liberty of changing the variable names and function names to make them more pertinent to what they're being used for.
/* Catalog Client Script */
function onLoad() {
var requestedFor = g_form.getValue('requested_for');
var ga_asset = new GlideAjax('GetAssetAssigneeDetails');
ga_asset.addParam('sysparm_name', 'RetrieveAssetDetails');
ga_asset.addParam('sysparm_req_for', requestedFor);
ga_asset.getXMLAnswer(assetResponse);
function assetResponse(answer) {
//var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var returneddata = JSON.parse(answer);
alert("Requestor has and existing Asset" + returneddata.assetDesc + ", with the end date as " + returneddata.endDate);
return false;
}
}
}
/* Script Include */
var GetAssetAssigneeDetails = Class.create();
GetAssetAssigneeDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
RetrieveAssetDetails: function () {
var reqUsr = this.getParameter('sysparm_req_for');
var gr_asset = new GlideRecord('device_asset');
gr_asset.addQuery('assigned_to', reqUsr);
gr_asset.setLimit(1);
gr_asset.query();
if (gr_asset.next()) {
var results = {
"endDate": gr_asset.getValue('end_date'),
"assetDesc": gr_asset.getValue('asset_description')
};
return JSON.stringify(results);
}
return false;
},
type: 'GetAssetAssigneeDetails'
});
Note: I have not tested out the code. Consider debugging both scripts if you come across any issues.
Hope this helps.