Auto-populate Company and Contract when creating incident

mitkomitashki
Tera Contributor

Hello,

Most of our incidents are opened using SolarWinds integration. We are assigning CI to each Incident and we want to auto-populate CIs Company and Contract fields in the Incident form. I am thinking about Business rule but is it the best way to do it? And if it is do I need to use script to populate this fields?

1 ACCEPTED SOLUTION

Dubz
Mega Sage

If the incidents are being opened automatically via the integration then the best option is a before insert business rule. It should be a fairly simple rule, you just need to change the company and contract to a value that you can dot-walk to via the CI field.

 

current.company = current.cmdb_ci.company;
current.contract = current.cmdb_ci.ast_contract;

View solution in original post

9 REPLIES 9

Company field is OK - it is auto populated using Business rule but Contract field stays empty. 

I'm not familiar with the contract_rel_ci table so i can't really advise you on that front. 

 

if your CI is linked to the contract via that table rather than a direct reference field then you'll need to glide into that table, find the right record and return the contract detail from there. The script below is the logic but i don't know if the field names are correct.

 

var gr = new GlideRecord('contract_rel_ci');
gr.addQuery('cmdb_ci', current.sys_id);
gr.query();

while(gr.next()){
var contract = gr.getValue('ast_contract');
current.ast_contract = contract;
}

I think that the following code is working. Is it OK?

ci_item and contract are column names in contract_rel_ci table.

 

 

 

	var gr = new GlideRecord('contract_rel_ci');
	gr.addQuery('ci_item', current.cmdb_ci);
	gr.query();

	while (gr.next())
		{
		var contract = gr.getValue('contract');
		current.contract = contract;
		}

If it works, then it is good 🙂

Midhun1
Giga Guru

HI,

You can use before insert business rule to populate the same. Yes you need to use glide record class to populate the CI company and contract to incident.