Auto populate configuration item when hostname is filled.

Anshika2
Kilo Expert

Hi, I was having one field on catalog task named 'hostname'. When this field is filled, it should auto populate the configuration item where configuration item is a reference field and hostname is single line text field. And when configuration item fills then it should also get copied on requested item form after saving the form.

But I was facing an error while doing this... Error : 'Match not found'.

Scripts are given below: Script include

var Populate_cmdb = Class.create();
Populate_cmdb.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    getID: function() {
        
        var asset = this.getParameter('sysparm_item');
        if(asset != ''){
            var gr = new GlideRecord('cmdb_ci_pc_hardware');
            gr.addQuery('name',asset);
            gr.query();
            if(gr.next()){
                return gr.name;
            }
        }

    type: 'Populate_cmdb'
    }
});

Client Script :

var Populate_cmdb = Class.create();
Populate_cmdb.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    getID: function() {
        
        var asset = this.getParameter('sysparm_item');
        if(asset != ''){
            var gr = new GlideRecord('cmdb_ci_pc_hardware');
            gr.addQuery('name',asset);
            gr.query();
            if(gr.next()){
                return gr.name;
            }
        }

    type: 'Populate_cmdb'
    }
}); 

}

 

Can anyone help with the same? I think due to reference field 'configuration item' I should capture sysid. 

 

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

You should return gr.sys_id.toString();

 

You should also write a business rule in task table after update

var req = new GlideRecord('sc_req_item');

req.get(current.request_item.sys_id);

req.configuration_item = current.configuration_item ;// Use correct field name

req.update();

View solution in original post

2 REPLIES 2

Palak Gupta
Tera Guru
Tera Guru

Hi there!

I think you missed to paste Client Script  section correctly. Please update the same.

Regards,

Palak

suvro
Mega Sage
Mega Sage

You should return gr.sys_id.toString();

 

You should also write a business rule in task table after update

var req = new GlideRecord('sc_req_item');

req.get(current.request_item.sys_id);

req.configuration_item = current.configuration_item ;// Use correct field name

req.update();