GlideAjax query

J_31
Kilo Sage

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

}

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

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 šŸ™‚

Best Regards
Aman Kumar

View solution in original post

26 REPLIES 26

Yes, that is the issue. Hence 1st alert also not getting.

 

Just remove it from the form layout and add check the back-end name of field by right clicking on it and show - field_name.

 

Add the correct field name and test it, it will work!.

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Hey,

You have to check, which field is valid and which one you want to deactivate, never a good idea of having two active fields with same value, will be confusing going forward as well,

So, please assess what you need and what you don't, for now change the value and run your client script and verify

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions šŸ™‚

Best Regards
Aman Kumar