VMware Cloud Community
ahola
Enthusiast
Enthusiast

Create vCAC entity using vCAC plugin? Issue with LocalDateTime?

I need some help creating a vCAC entity using the vCAC plugin. Here is the code snippet that I use:

// Inputs: host, entitySetName, propertyNames[], propertyValues[]

var modelName = 'ManagementModelEntities.svc';

var links = null;

var headers = null;

var inputProperties = new Properties();

for (var i = propertyNames.length - 1; i >= 0; i -= 1) {

  inputProperties.put(propertyNames[i], propertyValues[i]);  

}

var rEntity = vCACEntityManager.

  createModelEntity(host.id, modelName, entitySetName, inputProperties, links, headers);

if (rEntity == null) {

  throw "Unable to create " + entitySetName + " entity";

}

else {

  System.log("Created " + entitySetName + " entity");

}

However, this snippet fails with the following error:

    Unable to convert java.lang.String into org.joda.time.LocalDateTime (Workflow:CreateEntity / Create Entity (item1)#11)


I then tried with the following lines but with no luck:


inputProperties.put('CreatedDate', new org.joda.time.LocalDateTime(1972, 12, 3, 0, 0));

inputProperties.put('LastModifiedDate', new org.joda.time.LocalDateTime(1972, 12, 3, 0, 0));

I am having trouble finding a way to specify values for these two properties: CreatedDate & LastModifiedDate (the datatype being: org.joda.time.LocalDateTime).

Appreciate any help.

Tags (3)
0 Kudos
4 Replies
vdimitrov
Contributor
Contributor

Hi,

from the provided code snippet, I cannot see the types of the input properties you're using, but according to the error message, you're trying to convert a string value to a date which the plug-in will not do automatically for you. The way this is designed to work is by using the Date type of vCO. Here's an example which is verified to work:

var modelName = 'ManagementModelEntities.svc';

var entitySetName = "UserLogs";

var links = null;

var headers = null;

var inputProperties = new Properties();

//one way of doing this is by constructing the Date by yourself, check the API for more details.

var date = new Date();

//another way is by using an input parameter of type Date (presentation or attribute), in this case 'inputParameterDate' is of type Date and is populated from the workflow presentation.

var date = inputParameterDate;

inputProperties.put("UserName", "user@vmware.com");

inputProperties.put("Message", "Some logs");

inputProperties.put("Type", 0);

inputProperties.put("Timestamp", date);

var rEntity = vCACEntityManager.createModelEntity(host.id, modelName, entitySetName, inputProperties, links, headers);

Hope that helps.

ahola
Enthusiast
Enthusiast

I created a workflow with just one scriptable task passing in "vcacHost" as the only parameter - and used your snippet for the scriptable task. However, it fails with the same error as well. See error below:

[2013-08-13 04:46:05.616] [I] Unable to convert org.mozilla.javascript.NativeDate into org.joda.time.LocalDateTime (Workflow:test1 / Scriptable task (item1)#17)

Added attachment (test1.workflow) Message was edited by: ahola

0 Kudos
Burke-
VMware Employee
VMware Employee

This is a known bug that will be addressed in an upcoming build of the vCAC plug-in. I ran into it as well Smiley Wink

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Burke-
VMware Employee
VMware Employee

Please try the Technical Preview build of the plug-in here: vCAC plug-in technical preview

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos