updates with createOrUpdateCI versus glide record

tenagra
Kilo Expert

I'm working on a Script Include that will update cmdb ci records with specific information based.  This will be done via a schedule job and some discovery business rules.  

My original thinking was to use something similar to the code below so I could handle everything in the Script Includes.  However, when testing the code below, if I call getRecord and then getNewRecord, getNewRecord doesn't actually return a value.  The opposite is true of I run it in reverse.  I assume this is because of the While (next()) loop that is being run (it not, please correct me).  A getValue() wouldn't return a value.

While I could likely work around the issue, a thought struck me about using the createOrUpdateCI() API.  This would allow me to manage a JSON object, rather than a glide record object, bypassing the while(next()) issue  However, I know it would engage the identification engine, which I don't see as a major concern, but I could be way off on that assumption.

So, I wanted to pose the question to the community about any pro/cons of using a GlideRecord versus using a createOrUpdateCI() and/or if there are some best practices around it.  All input is welcome.

var CIGRTest = Class.create();
CIGRTest.prototype = {
    initialize: function(sysid) 
	{
		this.gr = new GlideRecord('cmdb_ci');
		this.gr.addQuery('sys_id', sysid);
		this.gr.query();
		gs.print('Record Count = ' + this.gr.getRowCount());
    },
	getRecord: function()
	{
		gs.print('--- Staring getRecord()------');
		while (this.gr.next())
			{var name = this.gr.getValue('name');gs.print('CI Name = ' + name);	}
	},
	getNewRecord: function()
	{
		gs.print('--- Staring getNewRecord()------');
		while (this.gr.next())
			{var name = this.gr.getValue('name'); gs.print('CI Name = ' + name);}
	},
    type: 'CIGRTest'
};

 

 

Thanks,

Nathan

7 REPLIES 7

Mark it answered or Solved, so that it will be helpful for others in future.


Please mark this response as correct or helpful if it assisted you with your question.

Won't let me mark my own response as 'Solved'.  

Yes. It doesnt allow. You can rename the question as [Solved]: Question


Please mark this response as correct or helpful if it assisted you with your question.