# Passing Multiple Values within CommandValue for more advanced flows

**URL:** <https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484>\
**Category:** V5 Tutorial\
**Created:** [March 4, 2019, 1:56am UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484 "2019-03-04T01:56:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [March 4, 2019, 1:56am UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/1 "2019-03-04T01:56:47Z")

</div>

Although probably not a common scenario, I hit a case where I needed to pass several values through an execute automation command and I have come up with an alternate solution available now using scripts to pass multiple variables as JSON.  
I adopted this approach over using program settings as like the ‘on the fly’ flow plus some scenarios may not allow for it.

 ![image](https://forum.sambapos.com/uploads/default/original/3X/2/2/222f1bb94ab4e50d20f096a45b26e295f0484d3a.png)

```
function newValues(input) {
	var input =input.toString();
	var jsonArray = {};
	var splitParams = input.split(',');
	for (var p = 0; p < splitParams.length; p++) {
		var singleParam = splitParams[p];
		var splitSingleParam	= singleParam.split('=');
		var paramName = splitSingleParam[0].toString();
		var paramValue = splitSingleParam[1].toString();
		jsonArray[paramName]	= paramValue;
	}
	return JSON.stringify(jsonArray);
}

function getValue(input,getValue){
	var jsonArray = JSON.parse(input);
	return jsonArray[getValue]
}

function addValues(input,newValues){
	if(input){
		var jsonArray = JSON.parse(input);
	}else{
		var jsonArray = {};
	}
	var splitParams = newValues.split(',');
	for (var p = 0; p < splitParams.length; p++) {
		var singleParam = splitParams[p];
		var splitSingleParam	= singleParam.split('=');
		var paramName = splitSingleParam[0].toString();
		var paramValue = splitSingleParam[1].toString();
		jsonArray[paramName]	= paramValue;
	}
	return JSON.stringify(jsonArray);
}

```

You would then place multiple values in the command value field using a CALL which will render as a JSON string for parsing in the rule later.

The scripts could probably do with some refinement and verification and you would need to be careful with special characters including quotes, double quotes, comma, colons and curly brackets which would interfere with JSON format. Be sure to test using show message or ask question to display values and check they are as expected.

 ![image](https://forum.sambapos.com/uploads/default/original/3X/1/5/1550d88efb7d19fb87845b6a1a8bcc5cb7d418dc.png)

Values should be entered as a comma separated list of name=value ie;  
`'<name1>=<value1>,<name2>=<value2>,<name3>=<value3>'`  
There is no limit to the number of name=value pairs.  
In my example I used [?Prompt] for values to be entered for testing but you should be able to use most system variables available to the rule event or scenario used.

 ![image](https://forum.sambapos.com/uploads/default/original/3X/d/9/d96ea5b2b0b26f3c714377d97e061918e6b9d040.png)  
Calling values needs the JSON sting in [:CommandValue] input first followed by the name for the value you wish to call ie;  
`'[:CommandValue]','<name1>'`

 ![image](https://forum.sambapos.com/uploads/default/original/3X/3/6/36e3c00d4c6525f25d3bd70180aef459700eb094.png)

 ![image](https://forum.sambapos.com/uploads/default/original/3X/8/2/8234bb2a77ebecdf477d24d9b7918ec712f91e93.png)

---

<div class="post-metadata">

**Author:** ![Shivan](https://forum.sambapos.com/user_avatar/forum.sambapos.com/shivan/32/27314_2.png) [@Shivan](https://forum.sambapos.com/u/Shivan)\
**Post date:** [March 4, 2019, 2:51am UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/2 "2019-03-04T02:51:12Z")

</div>

Interesting.

Is there a way we can create like a drop-down menu with a list of options using this type of method?

---

<div class="post-metadata">

**Author:** ![Jesse](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jesse/32/61493_2.png) [@Jesse](https://forum.sambapos.com/u/Jesse)\
**Post date:** [March 4, 2019, 4:28am UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/3 "2019-03-04T04:28:11Z")

</div>

That is awesome @JTRTech love your last couple tutorials I am sure people can get good use out of those.

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [March 4, 2019, 12:07pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/4 "2019-03-04T12:07:29Z")

</div>

Sure you can set drop-down in [?prompt]

---

<div class="post-metadata">

**Author:** ![Shivan](https://forum.sambapos.com/user_avatar/forum.sambapos.com/shivan/32/27314_2.png) [@Shivan](https://forum.sambapos.com/u/Shivan)\
**Post date:** [March 4, 2019, 1:42pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/5 "2019-03-04T13:42:08Z")

</div>

Really? How? Is there a command we add to the [?prompt] im unaware of?

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [March 4, 2019, 1:54pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/6 "2019-03-04T13:54:23Z")

</div>

Sure there is something in the mask, comma separated list, its on forum somewhere, was playing with it a few weeks ago.

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [March 4, 2019, 1:55pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/7 "2019-03-04T13:55:11Z")

</div>

@Shivan

> [@\[?Prompt\] dropdown prompt flag & values](https://forum.sambapos.com/t/prompt-dropdown-prompt-flag-values/7928/3):
>
> Awesome, hopefully it might except tags/scripts slight_smile

Pipe not comma separated.

`[?Choose a value;;<option1>|<option2>|<option3>|<option4>]`

Sure 3rd section is mask, so its alternate to mask since dropdown would surpass the need for a mask.

---

<div class="post-metadata">

**Author:** ![Shivan](https://forum.sambapos.com/user_avatar/forum.sambapos.com/shivan/32/27314_2.png) [@Shivan](https://forum.sambapos.com/u/Shivan)\
**Post date:** [March 4, 2019, 2:03pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/8 "2019-03-04T14:03:40Z")

</div>

Ohh I never saw that before.

Thanks for the reference.

---

<div class="post-metadata">

**Author:** ![Shivan](https://forum.sambapos.com/user_avatar/forum.sambapos.com/shivan/32/27314_2.png) [@Shivan](https://forum.sambapos.com/u/Shivan)\
**Post date:** [March 4, 2019, 3:41pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/9 "2019-03-04T15:41:53Z")

</div>

Works Perfectly. Thanks for that 🙂

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [March 4, 2019, 5:24pm UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/10 "2019-03-04T17:24:59Z")

</div>

Didnt say in firt post but you can also add values and extend the JSON.

{CALL:commandValue.addValues(’[:CommandValue]’,’\<name8\>=\<value8\>,\<name9\>=\<value9\>’)} will add the new values to the input command value array.

I did add a little validation into that to take into account if the input commandvalue doesn’t have anything. May not work if input isnt valid JSON though so again test well.

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [September 13, 2019, 2:20am UTC](https://forum.sambapos.com/t/passing-multiple-values-within-commandvalue-for-more-advanced-flows/19484/11 "2019-09-13T02:20:42Z")

</div>

Unfortunately it seems {=dlg.AskQuestion()] doesnt work within the {CALL:x} which is a shame. Unless Ive missed something or anyone has any bright ideas.  
Could call from within the script i guess but is counter the original aim of this idea.
