- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2025 12:06 PM
Hello All:
Despite it all, after 15 years, i'm revisiting Script Includes. LOL.
I don't do them much, so here is a dumb question.
I'm attempting to restrict users from requesting duplicate service accounts.
In my form, I'm also dictating the naming convention.
So when they enter a new name, i want to query my Service Account table to:
1. Validate its not already there
2. It hasn't been Deactivated
So, On my catalog variable serv_acc_name
On change, I'm calling my script include to pull back any record with that name
So the answer i get is populated
Serv Acct ={"po_dcom_ticket":{"display_value":"RITM0000013","sys_id":"d4c1edc5db8783000d95561bdc9619aa"},"po_name":"xx-SVC-T-xxxx","po_type":"svc"}
but when i attempt to get get the po_dcom_ticket value it returns object object.
Help.
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var svcName = newValue;
//findAccount(svcName);
var ga1 = new GlideAjax('getServAccInfo');
ga1.addParam('sysparm_name', 'getServAccInfo');
ga1.addParam('sysparm_acc_type', 'svc');
ga1.addParam('sysparm_acc_name', svcName);
ga1.getXML(updateFields);
}
function updateFields(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var aObj = JSON.parse(answer);
var deComm = aObj.po_name;
alert("the decom ticket is "+deComm);
}
Script Include
var getServAccInfo = Class.create();
getServAccInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServAccInfo : function() {
var accType = this.getParameter('sysparm_acc_type');
var accName = this.getParameter('sysparm_acc_name');
var u = new GlideRecord('u_service_accounts');
u.addQuery('u_nam',accName);
u.query();
var uObj = {};
if (u.next()) {
uObj = {
"po_name" : u.getValue('u_nam'),
"po_type" : u.getValue('u_category'),
"po_dept" : {
"sys_id" : u.getValue('u_decom_ticket'),
"display_value" : u.u_decom_ticket.getDisplayValue()
}
};
}
var answer = new JSON().encode(uObj);
gs.log('Serv Acct =' + answer);
return answer;
},
type: 'getServAccInfo'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2025 05:23 AM - edited 10-30-2025 05:24 AM
Thanks all.
I finally got to my answer.
Unfortunately, I could not get the RITM # to display from the SI.
So I simplified the SI to only return the sys_id of the RITM Decom Ticket.
Then used a GlideRecord in my client script to query task.
To the best solution but it works.
No matter which option I used from your comments, getting the RITM Number to Display in my CLient script always returned Object_object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2025 06:51 PM
I think there is a good chance that there is a name duplicate of the script include considering the issues and logging discrepancies. If not, now it should at least be a trivial exercise to get the script include to return the expected value as you are able to put a value in server-side and subsequently access it client-side.