Populate cmdb_ci field on incident form

Dan Brown2
Kilo Sage

Hello,

I have a onChange client script for populating the cmdb_ci field when the caller is manually selected - http://wiki.servicenow.com/index.php?title=Find_Computer_Assigned_to_Caller_and_Populate_CI_Field#gs...

But when a incident is raised by email or self service, then obviously this is not populated.   Are there any best practice Business Rules or other ways that the cmdb_ci can be populated in these circumstances?

Cheers,

Dan

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dan,



Have a business rule before insert and determine the caller and based on that fetch value of cmdb_ci. Condition for the business rule should be contact type is email or self service because for this condition you want to execute it


i.e.


Business rule script


var caller = current.caller_id;


var gr = new GlideRecord('cmdb_ci_computer'); //Table your computers reside in


gr.addQuery('assigned_to', caller );


gr.query();


if(gr.next()){


current.cmdb_ci = gr.sys_id;


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dan,



Have a business rule before insert and determine the caller and based on that fetch value of cmdb_ci. Condition for the business rule should be contact type is email or self service because for this condition you want to execute it


i.e.


Business rule script


var caller = current.caller_id;


var gr = new GlideRecord('cmdb_ci_computer'); //Table your computers reside in


gr.addQuery('assigned_to', caller );


gr.query();


if(gr.next()){


current.cmdb_ci = gr.sys_id;


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Vladimir Kobeti
Giga Guru

Hi Dan,



I guess a simple Business Rule "Before" "Update" should do the trick for you. A short untested snippet following the example:



var gr = new GlideRecord('cmdb_ci_computer');


    gr.addQuery('assigned_to', current.caller_id);


    gr.query();


    if(gr.next()){


    current.setValue('cmdb_ci', gr.sys_id);


    }




ananthagowraram
Mega Expert

Hi Dan,



Client Scripts will be working for the form level.You have a before business rule to populate cmdb when assigned to is changing/inserting.



Regards


Anantha Gowraram


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dan,



Hope you got the context with my script and it will help you in taking your approach. Thanks for marking the answer as correct. Could you also mark it helpful and hit like. Thanks in advance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader