Solved

Problem extracting the vmGUID in a Workflow using Javascript

  • 17 October 2022
  • 4 replies
  • 162 views

Badge +2

 

Hi,

I want to work with VMUtilities in Workflows.

Therefore, I created a simple workflow to extract the vmGUID using RestAPI.

 

 

The the first step created 2 Variables, on with the name of the VM  and the other for my vShpere-Client:

 

 

As the first activity I use HttpClient to get the client details including the vmGUID

 

 

1. Solution:

In the next step I’m using the activity «PowerOn», insert the two variable and try to extract the vmGUID from previous output:

 

To extract the vmGUID, I used the example I found in documentation and changed it to suite my needs.

https://documentation.commvault.com/v11/essential/132060_specifying_script_to_retrieve_input_value_for_workflow_activity.html

 

 

 

 

I get the following errors:

org.jdom2.input.JDOMParseException: Error on line 2: Element type "vm" must be followed by either attribute specifications, ">" or "/>".

VMOperationsHandler     : [PowerOn (PowerOn_1)] ERROR: failed to encode xml

 

2. Solution:

 Then I thought I could put these lines into the “OnStart Script” of “PowerOn” and just put the resulting variable vmGUID as input:

 

 

 

 

This time I get these errors:

groovy.lang.MissingPropertyException: No such property: JSON for class: Script1

ProcessOnEnter          : [PowerOn (PowerOn_1)] ERROR: error evaluating onEnter script

 

 

I have attached the exported workflow, just in case someone wants to have a look at it.

 

icon

Best answer by christopherlecky 17 October 2022, 21:43

View original

4 replies

Userlevel 5
Badge +16

For the “poweron” activity in the “onscript start” section add the following line

workflow.setLocalVariable("vmGUID", vmGUID)

and in the inputs section change vmGUID to 

js:{workflow.getLocalVariable("vmGUID")}:js

 

 

Userlevel 5
Badge +16

I just noticed the error.

Change the language of your script from Java to Javascript.

Badge +2

Christopher, thanks a ton for your help.

I tried the solution of your first answer and got errors during execution of the “OnStart Script” until I saw the wrong selection of the language.

Now it’s working as expected.

I’m so glad I have a solution now after spending so much time.

Once again, thank you.

Userlevel 5
Badge +16

Christopher, thanks a ton for your help.

I tried the solution of your first answer and got errors during execution of the “OnStart Script” until I saw the wrong selection of the language.

Now it’s working as expected.

I’m so glad I have a solution now after spending so much time.

Once again, thank you.

No problem.

 

Reply