Add CI in the related list after creation/updation of KB article

roomawakar
Tera Contributor

HI All,

 

I have a requirement to add the CI in the related list of the KB Article form, once the KB Article is created or updated, the value of CI field also should get added/updated in the related list -"Configuration Item".

Can someone please tell me how to achieve it?

 

Related List table - "m2m_kb_ci"

 

Thanks,

Rooma

1 ACCEPTED SOLUTION

Najmuddin Mohd
Mega Sage

Hi @roomawakar ,

You can write a Business rule, with After Insert/ Update with the following script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.addInfoMessage('Inside business rule')
	var grKBCI = new GlideRecord('m2m_kb_ci');
	grKBCI.addQuery('kb_knowledge',current.sys_id);
	grKBCI.query();

	if(grKBCI.next()){
		gs.addInfoMessage('Inside IF BLOCK');
		grKBCI.cmdb_ci = current.cmdb_ci;
		grKBCI.update();
	} 
	else{
		gs.addInfoMessage('Inside Else block');
		grKBCI.initialize();
		grKBCI.kb_knowledge = current.sys_id;
		grKBCI.cmdb_ci = current.cmdb_ci;
		grKBCI.insert();
	}

})(current, previous);


If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

View solution in original post

1 REPLY 1

Najmuddin Mohd
Mega Sage

Hi @roomawakar ,

You can write a Business rule, with After Insert/ Update with the following script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.addInfoMessage('Inside business rule')
	var grKBCI = new GlideRecord('m2m_kb_ci');
	grKBCI.addQuery('kb_knowledge',current.sys_id);
	grKBCI.query();

	if(grKBCI.next()){
		gs.addInfoMessage('Inside IF BLOCK');
		grKBCI.cmdb_ci = current.cmdb_ci;
		grKBCI.update();
	} 
	else{
		gs.addInfoMessage('Inside Else block');
		grKBCI.initialize();
		grKBCI.kb_knowledge = current.sys_id;
		grKBCI.cmdb_ci = current.cmdb_ci;
		grKBCI.insert();
	}

})(current, previous);


If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.