VMware Cloud Community
goraut
Contributor
Contributor
Jump to solution

Get all elements for a switch

I'm trying to get the total items for a switch element.

 

goraut_0-1677012229893.png

I don't know how to get all the elements for a switch, but I do know how to get the names of all the elements in the current workflow, and I want to filter out all the script tasks that call the 'clear' script task.

 

This is my code:

System.log(workflow.rootWorkflow.name)
System.log(workflow.rootWorkflow.description)
System.log("# items: " + workflow.rootWorkflow.numberOfItem)
var items = workflow.rootWorkflow.items;
for each (var item in items) {

  System.log(">>> stack entry begin: "+ item.name );
  System.log(">>> stack:  "+ item.description );
  System.log("next: " + item.nextItem);
  //Erro
  //System.log("next: " + item.nextItem.name);

}

Thanks

Labels (1)
  • Hi

Reply
0 Kudos
1 Solution

Accepted Solutions
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @goraut,

welcome in the VMware Community.

You ask a very interesting question. The WorkflowSwitchItem is not documented in the Orchestrator API Explorer. As far as I can see it contains two methods outItems and conditions.

System.log(workflow.rootWorkflow.name)
System.log(workflow.rootWorkflow.description)
System.log("# items: " + workflow.rootWorkflow.numberOfItem)
var items = workflow.rootWorkflow.items;
for each (var item in items) {

  System.log(">>> stack entry begin: "+ item.name );
  System.log(">>> stack:  "+ item.description );
  System.log("next: " + item.nextItem);
  //Erro
  //System.log("next: " + item.nextItem.name);

  if (item.constructor.name === "WorkflowSwitchItem") {
    item.outItems.forEach( function(outItem) {
      System.log(outItem.name);
    });
    item.conditions.forEach( function(condition) {
      System.log(condition);
    });
  }

}

outItems delivers an array of workflow items of the switch element and conditions delivers an array of strings with the conditions.

To get the total count of items for the switch element you can use

item.outItems.length

Best regards
Stefan


More interesting information at blog.stschnell.de

View solution in original post

2 Replies
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @goraut,

welcome in the VMware Community.

You ask a very interesting question. The WorkflowSwitchItem is not documented in the Orchestrator API Explorer. As far as I can see it contains two methods outItems and conditions.

System.log(workflow.rootWorkflow.name)
System.log(workflow.rootWorkflow.description)
System.log("# items: " + workflow.rootWorkflow.numberOfItem)
var items = workflow.rootWorkflow.items;
for each (var item in items) {

  System.log(">>> stack entry begin: "+ item.name );
  System.log(">>> stack:  "+ item.description );
  System.log("next: " + item.nextItem);
  //Erro
  //System.log("next: " + item.nextItem.name);

  if (item.constructor.name === "WorkflowSwitchItem") {
    item.outItems.forEach( function(outItem) {
      System.log(outItem.name);
    });
    item.conditions.forEach( function(condition) {
      System.log(condition);
    });
  }

}

outItems delivers an array of workflow items of the switch element and conditions delivers an array of strings with the conditions.

To get the total count of items for the switch element you can use

item.outItems.length

Best regards
Stefan


More interesting information at blog.stschnell.de

goraut
Contributor
Contributor
Jump to solution

Thanks @StefanSchnell