CRUD operation – updating a model entity

Here is a really simple script which updates a blueprint description.


var entity = blueprint.getEntity();
var entityProperties = entity.getProperties();
entityProperties.put("VirtualMachineTemplateDescription", description);

var host = Server.findForType("vCAC:VCACHost", entity.hostId);

vCACEntityManager.updateModelEntity(entity.hostId, entity.modelName, entity.entitySetName, entity.entityKey, entityProperties, entity.getLinks(host), null);

It’s very simple but it demonstrates how to use the updateModelEntity method. In the example abve, you pass in the blueprint value and a description, or you could calculate this on the fly.

The first three lines are key:


var entity = blueprint.getEntity();
var entityProperties = entity.getProperties();
entityProperties.put("VirtualMachineTemplateDescription", description);

It basically gets the blueprint entity, grabs all the properties in to an object and then puts (overrides) the VirtualMachineTemplateDescription properties with a value provided. Just an example but by using LinqPad, you can look through the ODATA objects to update whatever value is associated to the the blueprint.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s