- 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 06:14 PM
That makes sense To me but id have no way to do it myself
so you're saying
on change,
query cmdb_ci table and if incident.subcategory = cmdb_ci.Display name
set the value of cmdb_ci field to the sys_id of the record that matches in cmdb_ci?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 06:23 PM
Carl,
You understood that correct.
~Raghu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 06:29 PM
Cool! Any way you'd provide that script?
Get Outlook for iOS<https://aka.ms/o0ukef>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 06:47 PM
Carl,
This is not a recommended method by ServiceNow but i am giving you the script only to over come the issue right now. Would strongly suggest workarounds.
Script:
Make sure you are adding the right field names and use alert conditions if you want to debug.
var sub = g_form.getDisplayValue('subcategory');
var sys;
var ci = new GlideRecord('cmdb_ci');
ci.addQuery('name',sub);
ci.query();
while(ci.next())
{
sys = ci.sys_id;
}
g_form.setValue('cmdb_ci',sys);
*This will work only when you have a condiguration item with the same display name as of subcategory.
Let me know how it goes and mark Helpful or Answered and make help improve community experience.
~Raghu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2017 07:14 PM
Thank you for this. I'm curious why this would not be recommended.
Is there a better way?
Get Outlook for iOS<https://aka.ms/o0ukef>