Update fields EOL / EOS of cmdb_ci table depending upon values in the custom table. [ See description for details]

Sachin Gavhane
Giga Guru

I have created a custom table "eoleos" as shown below:

find_real_file.png

field --> Type (choice) Choices are : Operating System , Database Server , Network Device , ATM

EOL/ EOL are date and remaining all fields are string.

User will enter details in all the above fields in the custom table "eoleos".

Requirement is : 

When insert or update on above table "eoleos"

if type == Operating System

then

Match Name & version/Model mentioned in above custom table with CMDB_CI table (Operating System, OS version) and update OS EOL & OS EOS of cmdb_ci table from the above custom table.

can someone help me in this requirement.

@shloke04 can you please help me

appreciate your time and efforts

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

@Sachin Gavhane 

Couple of points to note here:

1) Updating CMDB CI table with EOL and EOS values from your custom table is okay but which class of CMDB CI you want to update here?

So please make sure you update the correct class when updating the values, I am sharing the script to be used here you just need to update the correct table Name here in script below it can be Hardware, Network or Computer or the class you want:

BR Details:

Table Name: eoleos

When: After Insert and Update

Condition: Type is Operating System

Script:

Current in script below refer to EOLOS table field object. So replace the field Name and value properly and you should be good with your requirement.

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

	// Add your code here
	updateCITable(current);
	
	function updateCITable(current){
		var gr = new GlideRecord('Table Name here');
		gr.addQuery('name',current.name);
		gr.addQuery('version',current.version);
		gr.addQuery('model_id',current.model);
		gr.query();
		while(gr.next()){
			gr.FIELD_NAME = current.EOL_FIELD_NAME;
			gr.FIELD_NAME = current.EOS_FIELD_NAME;
			gr.update();
			
		}
		
	}

})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

7 REPLIES 7

Sourabh26
Giga Guru

Hi,

 

Use below script for your requirement - 

 

Business Rule - After (Insert and Update)

Table - eoleos

Condition - Type isOneOf "Operating System , Database Server , Network Device , ATM"

var name = current.name_field_name;
var version = current.version_field_name;
var grCmdb = new GlideRecord('cmdb_ci');
grCmdb.addQuery('operating_system_field',name);
grCmdb.addQuery('os_version',version);
grCmdb.query();
if(grCmdb.next()){
    current.eol_filed = grCmdb.os_eol_field_name;
    current.eos_filed = grCmdb.os_eos_field_name;
    current.update();
}

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh

Hi Sourabh,

can you help with the above requirement?

Hi @Sourabh 

i want to update the fields (eol/eos) of cmdb_ci table

so conent inside if we change right?

also many fields are not directly on cmdb_ci table then how it will work?

okay in that case do the below change on the shared script above - 

if(grCmdb.next()){

      grCmdb.os_eol_field_name = current.eol_filed;
      grCmdb.os_eos_field_name = current.eos_filed;

      grCmdb.update();

}

 

also many fields are not directly on cmdb_ci table then how it will work?

In that case you need to dot walk to that field or else use setValue() method to update the value on that field.

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh