- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 05:37 PM
Hi All,
Will anyone help me come up with a client script that will copy the value of a subcategory to the Configuration Item field? I can't write javascript and am in a hurry
I believe it it should be "on change" type.
Incident table
psuedo script
If "subcategory" changes to "anything", set "Configuration Item" to same as "subcategory"
Will copying the display name into that reference field work if they are the same?
Currently, I have a reporting issue with the way I've enhanced the form and think this may be the quickest fix Until we figure out how to fix the data issue we've created
if I had this script I could remove several ui policies and actions which are becoming confusing and sort of have me cornered at the moment.
Please let let me know if you can help.
Thanks in advance for your time and assistance!
regards, Carl
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 10:55 PM
first create script include mark that check box client callable
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ajaxFunction_LocationAjax : function() {
var fo='';
var customerID = this.getParameter('sysparm_custid'); //paramter from the client side
var ag = new GlideRecord('cmdb_ci');
ag.addQuery('name', customerID);
ag.query();
while (ag.next()) {
fo= ag.sys_id;
gs.log('value is :'+fo);
}
return fo;
},
type: 'test'
});
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var customerNo = g_form.getValue('subcategory');
var gajax = new GlideAjax('test'); // call the Script Include class
// call the public method
gajax.addParam('sysparm_name', 'ajaxFunction_LocationAjax');
// pass the sysID to the method
gajax.addParam('sysparm_custid', customerNo);
//callback function is used to return the result, passed to the getXML function
gajax.getXML(callBackLocation);
function callBackLocation(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
g_form.setValue('cmdb_ci', answer);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 05:42 PM
Assuming 'Subcategory' is a Reference Field to the CMDB table, and the field you want to populate is called 'u_ci_field'
On Change - Subcategory Field
g_form.setValue('u_ci_field',newValue);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 05:53 PM
Thanks Paul. The subcategory field is just a choice field. So the value is just the display name and not the sys_id.
that was my concern when asking if having the choice match the display name would work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 05:56 PM
Carl,
So do you have same sub category as existing configuration item as well ?
~Raghu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 06:02 PM
Yes. I'm planning on using the out of box field "subcategory" and the out of box "configuration item".
The values in the subcategory choices are the same as the display names on the cmdb_ci business services so they'll always match that way.
Currently, I have different cmdb_ci reference fields for a few categories and it's caused a lot of mess so I'm trying to clean it up and I think this may do the trick.
Get Outlook for iOS<https://aka.ms/o0ukef>