VMware Cloud Community
philippbck
Contributor
Contributor
Jump to solution

Return Business State of Workflow Items

Hello,

I am currently developing a validation workflow. The workflow object is set as input paremeter. This validation workflow should also check whether the business state is set on the workflow items of a workflow. Is it possible to return the business state´s of all workflow items from a workflow?

Thanks for help.

1 Solution

Accepted Solutions
jasnyder
Hot Shot
Hot Shot
Jump to solution

As far as I could tell there is no way to get the business status set by each workflow item.  But I did figure out a way to get it.  You need to use Java reflection to do it.  This is not out of the box with vRO, but you can expose Java reflection libraries to the vRO scripting environment by using the following steps:

  1. Log in to the vRO control center
  2. Click System Properties
  3. Add a new property with the name com.vmware.scripting.rhino-class-shutter-file and the value = /var/lib/vco/app-server/conf/rhinofile
  4. SSH into the vRO appliance and create the /var/lib/vco/app-server/conf/rhinofile file with one line, the contents of that line should be

    java.lang.*

  5. Save the file
  6. Run chown vco:vco /var/lib/vco/app-server/conf/rhinofile
  7. Restart the vRO server by running service vco-server restart

After restart, anything in the java.lang.* namespace is available including what we need is java.lang.Class.

Why do you need to do this?  Because with Java reflection you can call methods on objects that are public or private.  In this case, the underlying object is of type ch.dunes.model.workflow.WorkflowItem.  There is a method on that object called getBusinessStatusChange() which has not been exposed to the scripting environment in vRO.  It is a public method on the Java object, but you just can't call it without reflecting into the class to get access.

I have attached an example workflow that takes a Workflow as input, it iterates through all the workflow's items and spits out the item's name and its business status change.  If you do not check the box on an item in the workflow designer, this will return null, otherwise it returns a string containing the status entered next to the check box.

Script content:

//Get the WorkflowItem class for reflection

var wfItemClass = java.lang.Class.forName("ch.dunes.model.workflow.WorkflowItem");

var m = wfItemClass.getDeclaredMethod("getBusinessStatusChange"); 

//iterate through all WorkflowItems in the workflow

for (var i in WF.items)

{

    var wfItem = WF.items[i];   

   

    //Get the business status by invoking the non-exposed (but public) method getBusinessStatusChange()

    var businessStatus = m.invoke(wfItem)

   

    System.log(wfItem.name + " - " + businessStatus);

   

    if(businessStatus == null) {

        //Do something like throw an error or track it in some way

    }

   

}

Sample Output 1 - simple workflow:

[2017-11-17 23:50:51.369] [I] End - null

[2017-11-17 23:50:51.371] [I] Validate Workflow - test

Sample Output 2 - more complex workflow with numerous item types (these are all null because I didn't want to change the workflow):

[2017-11-17 23:57:43.758] [I] Active Directory? - null

[2017-11-17 23:57:43.761] [I] Member Servers? - null

[2017-11-17 23:57:43.770] [I] Set DC Info - null

[2017-11-17 23:57:43.773] [I] Set Member Info - null

[2017-11-17 23:57:43.775] [I] Multiple DCs? - null

[2017-11-17 23:57:43.778] [I] Generate ServerInfo - null

[2017-11-17 23:57:43.780] [I] Build First Domain Controller - W2K12 - null

[2017-11-17 23:57:43.783] [I] Continue Builds? - null

[2017-11-17 23:57:43.785] [I] Increase counter - null

[2017-11-17 23:57:43.787] [I] Build Additional Domain Controller - W2K12 - null

[2017-11-17 23:57:43.789] [I] CreateEnclave - null

[2017-11-17 23:57:43.791] [I] Set Networks - null

[2017-11-17 23:57:43.793] [I] Sleep - null

[2017-11-17 23:57:43.795] [I] Build First DC? - null

[2017-11-17 23:57:43.797] [I] Continue Builds? - null

[2017-11-17 23:57:43.799] [I] Do Nothing - null

[2017-11-17 23:57:43.801] [I] Windows Workstations? - null

[2017-11-17 23:57:43.804] [I] Windows DBs? - null

[2017-11-17 23:57:43.806] [I] Build Machine From Template - null

[2017-11-17 23:57:43.809] [I] Increase counter - null

[2017-11-17 23:57:43.811] [I] Set Workstation Info - null

[2017-11-17 23:57:43.814] [I] Build Machine From Template - null

[2017-11-17 23:57:43.816] [I] Increase counter - null

[2017-11-17 23:57:43.818] [I] Continue Builds? - null

[2017-11-17 23:57:43.821] [I] Scriptable task - null

[2017-11-17 23:57:43.824] [I] Continue Builds? - null

[2017-11-17 23:57:43.826] [I] Increase counter - null

[2017-11-17 23:57:43.829] [I] Exchange Servers? - null

[2017-11-17 23:57:43.831] [I] Scriptable task - null

[2017-11-17 23:57:43.833] [I] Continue Builds? - null

[2017-11-17 23:57:43.835] [I] Increase counter - null

[2017-11-17 23:57:43.837] [I] Linux Servers? - null

[2017-11-17 23:57:43.839] [I] Linux Servers? - null

[2017-11-17 23:57:43.842] [I] End - null

[2017-11-17 23:57:43.843] [I] Scriptable task - null

[2017-11-17 23:57:43.845] [I] Continue Builds? - null

[2017-11-17 23:57:43.847] [I] Build Machine From Template - null

[2017-11-17 23:57:43.849] [I] Increase counter - null

[2017-11-17 23:57:43.851] [I] Scriptable task - null

[2017-11-17 23:57:43.854] [I] Continue Builds? - null

[2017-11-17 23:57:43.856] [I] Build Machine From Template - null

[2017-11-17 23:57:43.858] [I] Increase counter - null

[2017-11-17 23:57:43.860] [I] Update Environment Record - null

[2017-11-17 23:57:43.863] [I] Set Env Record - null

[2017-11-17 23:57:43.865] [I] Update Inventory Table - null

[2017-11-17 23:57:43.867] [I] Monitor Async Tasks - null

[2017-11-17 23:57:43.869] [I] Track Token - null

[2017-11-17 23:57:43.871] [I] Track Token - null

[2017-11-17 23:57:43.873] [I] Track Token - null

[2017-11-17 23:57:43.875] [I] Track Token - null

[2017-11-17 23:57:43.877] [I] Track Token - null

[2017-11-17 23:57:43.879] [I] Track Token - null

[2017-11-17 23:57:43.881] [I] Track Token - null

[2017-11-17 23:57:43.883] [I] Acquire Lock - null

[2017-11-17 23:57:43.885] [I] Release Lock - null

[2017-11-17 23:57:43.887] [I] Acquire Lock - null

[2017-11-17 23:57:43.889] [I] Release Lock - null

[2017-11-17 23:57:43.891] [I] Insert Into Inventory Table - null

[2017-11-17 23:57:43.893] [I] Update Inventory Table - null

[2017-11-17 23:57:43.895] [I] Set Output - null

[2017-11-17 23:57:43.898] [I] Build SQL Server 2012 - W2K12 / R2 - null

[2017-11-17 23:57:43.900] [I] Build Exchange Server 2013 - W2K12 R2 - null

View solution in original post

2 Replies
jasnyder
Hot Shot
Hot Shot
Jump to solution

As far as I could tell there is no way to get the business status set by each workflow item.  But I did figure out a way to get it.  You need to use Java reflection to do it.  This is not out of the box with vRO, but you can expose Java reflection libraries to the vRO scripting environment by using the following steps:

  1. Log in to the vRO control center
  2. Click System Properties
  3. Add a new property with the name com.vmware.scripting.rhino-class-shutter-file and the value = /var/lib/vco/app-server/conf/rhinofile
  4. SSH into the vRO appliance and create the /var/lib/vco/app-server/conf/rhinofile file with one line, the contents of that line should be

    java.lang.*

  5. Save the file
  6. Run chown vco:vco /var/lib/vco/app-server/conf/rhinofile
  7. Restart the vRO server by running service vco-server restart

After restart, anything in the java.lang.* namespace is available including what we need is java.lang.Class.

Why do you need to do this?  Because with Java reflection you can call methods on objects that are public or private.  In this case, the underlying object is of type ch.dunes.model.workflow.WorkflowItem.  There is a method on that object called getBusinessStatusChange() which has not been exposed to the scripting environment in vRO.  It is a public method on the Java object, but you just can't call it without reflecting into the class to get access.

I have attached an example workflow that takes a Workflow as input, it iterates through all the workflow's items and spits out the item's name and its business status change.  If you do not check the box on an item in the workflow designer, this will return null, otherwise it returns a string containing the status entered next to the check box.

Script content:

//Get the WorkflowItem class for reflection

var wfItemClass = java.lang.Class.forName("ch.dunes.model.workflow.WorkflowItem");

var m = wfItemClass.getDeclaredMethod("getBusinessStatusChange"); 

//iterate through all WorkflowItems in the workflow

for (var i in WF.items)

{

    var wfItem = WF.items[i];   

   

    //Get the business status by invoking the non-exposed (but public) method getBusinessStatusChange()

    var businessStatus = m.invoke(wfItem)

   

    System.log(wfItem.name + " - " + businessStatus);

   

    if(businessStatus == null) {

        //Do something like throw an error or track it in some way

    }

   

}

Sample Output 1 - simple workflow:

[2017-11-17 23:50:51.369] [I] End - null

[2017-11-17 23:50:51.371] [I] Validate Workflow - test

Sample Output 2 - more complex workflow with numerous item types (these are all null because I didn't want to change the workflow):

[2017-11-17 23:57:43.758] [I] Active Directory? - null

[2017-11-17 23:57:43.761] [I] Member Servers? - null

[2017-11-17 23:57:43.770] [I] Set DC Info - null

[2017-11-17 23:57:43.773] [I] Set Member Info - null

[2017-11-17 23:57:43.775] [I] Multiple DCs? - null

[2017-11-17 23:57:43.778] [I] Generate ServerInfo - null

[2017-11-17 23:57:43.780] [I] Build First Domain Controller - W2K12 - null

[2017-11-17 23:57:43.783] [I] Continue Builds? - null

[2017-11-17 23:57:43.785] [I] Increase counter - null

[2017-11-17 23:57:43.787] [I] Build Additional Domain Controller - W2K12 - null

[2017-11-17 23:57:43.789] [I] CreateEnclave - null

[2017-11-17 23:57:43.791] [I] Set Networks - null

[2017-11-17 23:57:43.793] [I] Sleep - null

[2017-11-17 23:57:43.795] [I] Build First DC? - null

[2017-11-17 23:57:43.797] [I] Continue Builds? - null

[2017-11-17 23:57:43.799] [I] Do Nothing - null

[2017-11-17 23:57:43.801] [I] Windows Workstations? - null

[2017-11-17 23:57:43.804] [I] Windows DBs? - null

[2017-11-17 23:57:43.806] [I] Build Machine From Template - null

[2017-11-17 23:57:43.809] [I] Increase counter - null

[2017-11-17 23:57:43.811] [I] Set Workstation Info - null

[2017-11-17 23:57:43.814] [I] Build Machine From Template - null

[2017-11-17 23:57:43.816] [I] Increase counter - null

[2017-11-17 23:57:43.818] [I] Continue Builds? - null

[2017-11-17 23:57:43.821] [I] Scriptable task - null

[2017-11-17 23:57:43.824] [I] Continue Builds? - null

[2017-11-17 23:57:43.826] [I] Increase counter - null

[2017-11-17 23:57:43.829] [I] Exchange Servers? - null

[2017-11-17 23:57:43.831] [I] Scriptable task - null

[2017-11-17 23:57:43.833] [I] Continue Builds? - null

[2017-11-17 23:57:43.835] [I] Increase counter - null

[2017-11-17 23:57:43.837] [I] Linux Servers? - null

[2017-11-17 23:57:43.839] [I] Linux Servers? - null

[2017-11-17 23:57:43.842] [I] End - null

[2017-11-17 23:57:43.843] [I] Scriptable task - null

[2017-11-17 23:57:43.845] [I] Continue Builds? - null

[2017-11-17 23:57:43.847] [I] Build Machine From Template - null

[2017-11-17 23:57:43.849] [I] Increase counter - null

[2017-11-17 23:57:43.851] [I] Scriptable task - null

[2017-11-17 23:57:43.854] [I] Continue Builds? - null

[2017-11-17 23:57:43.856] [I] Build Machine From Template - null

[2017-11-17 23:57:43.858] [I] Increase counter - null

[2017-11-17 23:57:43.860] [I] Update Environment Record - null

[2017-11-17 23:57:43.863] [I] Set Env Record - null

[2017-11-17 23:57:43.865] [I] Update Inventory Table - null

[2017-11-17 23:57:43.867] [I] Monitor Async Tasks - null

[2017-11-17 23:57:43.869] [I] Track Token - null

[2017-11-17 23:57:43.871] [I] Track Token - null

[2017-11-17 23:57:43.873] [I] Track Token - null

[2017-11-17 23:57:43.875] [I] Track Token - null

[2017-11-17 23:57:43.877] [I] Track Token - null

[2017-11-17 23:57:43.879] [I] Track Token - null

[2017-11-17 23:57:43.881] [I] Track Token - null

[2017-11-17 23:57:43.883] [I] Acquire Lock - null

[2017-11-17 23:57:43.885] [I] Release Lock - null

[2017-11-17 23:57:43.887] [I] Acquire Lock - null

[2017-11-17 23:57:43.889] [I] Release Lock - null

[2017-11-17 23:57:43.891] [I] Insert Into Inventory Table - null

[2017-11-17 23:57:43.893] [I] Update Inventory Table - null

[2017-11-17 23:57:43.895] [I] Set Output - null

[2017-11-17 23:57:43.898] [I] Build SQL Server 2012 - W2K12 / R2 - null

[2017-11-17 23:57:43.900] [I] Build Exchange Server 2013 - W2K12 R2 - null

philippbck
Contributor
Contributor
Jump to solution

Thank you very much!!!! That is a perfect way I was looking for. Smiley Happy

0 Kudos