- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 04:53 AM
Hi
I am not sure why the value is not populated when I change the configuration item field value in Incident form . it updates when is save. Its suppose to update when I change the value in CI field.
Script Include
--------------------
var PopulateDemo = Class.create();
PopulateDemo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
popAssignmentGroup : function()
{
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id',this.getParameter('sysparm_cmdb_ci'));
gr.query();
if(gr.next())
{
return gr.support_group;
}
},
type: 'PopulateDemo'
});
Client Script
-----------------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('PopulateDemo');
ga.addParam('sysparam_name','popAssignmentGroup');
ga.addParam('sysparam_cmdb_ci',g_form.getValue('cmdb_ci'));
ga.getXML(getResponse);
function getResponse(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group',answer);
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 07:59 AM
Hey,
Try Below:
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('PopulateDemo');
ga.addParam('sysparm_name', 'popAssignmentGroup');
ga.addParam('sysparm_cmdb_ci', g_form.getValue("cmdb_ci"));
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group', answer);
}
}
Script Include
var PopulateDemo = Class.create();
PopulateDemo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
popAssignmentGroup : function(){
var cmdbCI = this.getParameter('sysparm_cmdb_ci');
var gr = new GlideRecord('cmdb_ci');
if(gr.get(cmdbCI){
return gr.getValue("support_group");
}
return;
},
type: 'PopulateDemo'
});
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions š
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 05:04 AM
I would assume the client script runs on the field cmdb_ci?
Try replacing this line:
ga.addParam('sysparam_cmdb_ci',g_form.getValue('cmdb_ci'));
with:
ga.addParam('sysparm_cmdb_ci', newValue);
Also, in your script include, try making it a habbit always to use .getValue(), so:
return gr.getValue('support_group');
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 05:12 AM
ga.addParam('sysparam_cmdb_ci', newValue);
New Value may not be the value entered in CMDB_ci field, what if it takes caller information if I enter that in another field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 05:38 AM
if you configured, client script on-change of other fields. You have to use the
g_form.getValue('cmdb_ci'); // it will run this script and populate assignment group when that field value changed.
I would suggest to create client script on-change of cmdb_ci field.
Thanks!
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-15-2022 05:59 AM
Well, if you do run it on the client script on the cmdb_ci field, then the getValue will retrieve the stored value on the form, not the new one, thus newValue is correct. I don't see the use case for doing this on change of Caller_id, since the cmdb_ci should have not relation to the caller, and you are setting the assignment group based on the cmdb_ci field.
Best regards,
Sebastian Laursen