Fix Script to populate Fields

JamesT-1
Tera Contributor

I'm attempting to create a fix script that will populate two new fields on the incident form for all existing incidents.  The two fields (asset tag and serial number) are both dependent on the value of the Configuration item field. With the newly created onChange Client script these two new fields will auto populate with their respective values from the asset chosen in the Configuration item. Below is what I have so far that is not working. Can anyone provide some insight? Thanks.

 

var grIncident = new GlideRecord('incident');
grIncident.query();

while(grIncident.next()){

    gr.u_inc_asset_tag = gr.cmdb_ci.asset_tag;
    gr.u_inc_serial_number = gr.cmdb_ci.serial_number;
    gr.setWorkflow(false);
    gr.update();
}
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Your GlideRecord is instantiated as grIncident, but you are using gr. in the while loop.  Change all of these appearances to grIncident, and you should be closer.

View solution in original post

7 REPLIES 7

Wow, it was emptying the value of those new fields on incidents whose configuration item was not an asset then it populated the new fields for only those incidents who's config item was an asset. That was so cool! Thanks for your assistance gents.

Anubhav24
Mega Sage
Mega Sage

@JamesT-1 ,Your gliderecord object is "grIncident " and you are using "gr".

Please mark correct/helpful if my response helped you.

Debasis Pati
Tera Guru

Hello @JamesT-1 ,

Please try the below script

var grIncident = new GlideRecord('incident');
grIncident.query();

while (grIncident.next()) {
grIncident.u_inc_asset_tag = grIncident.cmdb_ci.asset_tag;
grIncident.u_inc_serial_number = grIncident.cmdb_ci.serial_number;
grIncident.setWorkflow(false);
grIncident.update();
}

the issue with your script was you have initializes the Gliderecord object as "grIncident" but mistekely you have done

gr.u_inc_asset_tag = gr.cmdb_ci.asset_tag;
    gr.u_inc_serial_number = gr.cmdb_ci.serial_number;
    gr.setWorkflow(false);
    gr.update();
instead use "grIncident" in place of gr it will resolve your issue.

Kindly mark it as accepted/helpful if this helps you.

Regards,
Debasis