Automation Workflow: How to convert string to array of string?

PhilipDAth
Kind of a big deal
Kind of a big deal

Automation Workflow: How to convert string to array of string?

Part of my workflow involves claiming an MX into a network.

 

I create a list of all suitable MX in inventory, and let the user choose one using "Create Prompt".  At this point, I now have a string which is the serial number of the MX I want to add to the network.

 

I would now like to use the atomic "Meraki - Claim Network Devices".  However, it requires an *array* of strings.

 

I can't figure out how to add a string to an array, or how to convert a string to an array.

I've tried creating a local variable which is an array of strings - but I can't find any operations that let me append to that array.

 

Help!

11 Replies 11
alemabrahao
Kind of a big deal
Kind of a big deal

I can think of three options.

You can try adding the "Create Array" action before calling "Meraki - Claim Network Devices," just put your string variable in square brackets.

Try using "Compose with json()" or try using the "Add to array variable" action to add your string.

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
PhilipDAth
Kind of a big deal
Kind of a big deal

I don't see any action to create an array?

PhilipDAth_0-1764524842657.png

>just put your string variable in square brackets.

 

Once I select a variable, it won't let me edit the field anymore to add brackets.

 

I can't see any actions like "Compose with JSON".

PhilipDAth_1-1764524918773.png

 

 

I ended up creating a one-line "Create With Python" script action like:

output = ["variable"]

It kinda seems wrong to drop back to coding when everything else is GUI point and click based.

 

enovak
Meraki Employee
Meraki Employee

@PhilipDAth 
In the Set Variables activity, you can combine free form text and other variables to create an array:

enovak_1-1764609903568.png

 

Network Platform Team
Workflows - Technical Marketing Engineer
enovak
Meraki Employee
Meraki Employee

@PhilipDAth We're working on enhancements for Arrays.  Currently, you can use a standard string to capture data, and you can append a string using a Set Variables Activity by selecting the string as the Variable to update and then select the same string as the New value along with the new string to append.

enovak_0-1764609583193.png

You can also assign a sting into a String Array, but you may need to format the String Array so that it is proper JSON, To do this I've used a Python Activity to clean up and properly format the JSON Array.

Network Platform Team
Workflows - Technical Marketing Engineer
PhilipDAth
Kind of a big deal
Kind of a big deal

Good tip!  I might try this out next time.

enovak
Meraki Employee
Meraki Employee

I'd also suggest checking out and posting questions in the Cisco Workflows Community 

Network Platform Team
Workflows - Technical Marketing Engineer
PhilipDAth
Kind of a big deal
Kind of a big deal

I find the Cisco Community hard to use.  It's like drowning in a sea of content.

Oren
Meraki Employee All-Star Meraki Employee All-Star
Meraki Employee All-Star

CC: @AmyReyes 

PhilipDAth
Kind of a big deal
Kind of a big deal

Here is an example challenge.  Pretend you have not used Cisco Community before.  Starting from the home page, tell me how long it takes you to find the "Cisco Workflows" community.
https://community.cisco.com/

 

I have used the Cisco Community.  I couldn't find it.  I gave up.

enovak
Meraki Employee
Meraki Employee

@PhilipDAth instead of Arrays, you may want to consider using Table Activities in Workflows.  You can Read your table from JSON, and then add or update rows.

Do keep in mind Persist Table. If you want to make changes to a table later, it must be made persistent. Otherwise, you will only be able to read from the table.

Recommend that you manually add columns individually in the Columns to Read section of the Table activity properties.

If you populate column headers from their source data the columns will only be populated at run time and you cannot use the column headers when creating a For Each loop.

Network Platform Team
Workflows - Technical Marketing Engineer
PhilipDAth
Kind of a big deal
Kind of a big deal

Thanks for the tip.  🙂

Get notified when there are additional replies to this discussion.