Script issue

Post your questions and help other users.

Moderator: Martin

Post Reply
sambarlick
Posts: 96
Joined: 27 Jul 2014 10:40

Script issue

Post by sambarlick » 08 Aug 2014 14:29

Hi guys,

I am working on a flow that has a multiple choice input dialog.

The flow firsts ask a simple yes no question, then no executes the multiple choice dialog.

From the result of the multiple choice dialog i want to change the value of the sleep function.

This is the script that feeds into the sleep function...

if (value == 1)
{
time=2d;
}
if (value == 2)
{
time=3d;
}
if (value == 3)
{
time=4d;
}
if (value == 4)
{
time=5d;
}
else
{
time=1d;
}

I then write time as a variable in the sleep function.

The flow then stops resulting in an error.

What am i doing wrong?

Sam

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Script issue

Post by Martin » 08 Aug 2014 17:41

Hi,

The values assigned to variable time are wrong, you can either assign the number of milliseconds or a string. I would recommend to use a string in this case, since the duration is very long (note the double quotes):

Code: Select all

if (value == 1)
{
time="2d";
}
if (value == 2)
{
time="3d";
}
...
Be careful with the else on the last if, this will usually make the script assign "1d" to time when you select 1, 2 or 3.

You could also use a list and the variable index to make the script a bit shorter (index is provided by the input dialog 0=first element, 1=second element etc.):

Code: Select all

durations = newList("1d", "2d", "3d", "4d", "5d");
time = getElement(durations, index);
or directly create the time using the selected index in the dialog:

Code: Select all

time = (index + 1) + "d";
The first selected element is at index 0 which would be transformed to "1d".

or set the values of the dialog directly to the values you want to use in the sleep action, for example use the following text in field LIST VALUES of the input dialog action:
1d,2d,3d,4d,5d

Then directly use the inline expression {value} in action Sleep:

Regards,
Martin

sambarlick
Posts: 96
Joined: 27 Jul 2014 10:40

Re: Script issue

Post by sambarlick » 10 Aug 2014 14:32

Hi Martin,

Unfortunatly those methods didn't work. I have attached the flow, maybe you could see if i have done anything wrong prior to that script.

Much appreciated,
Sam
Attachments
flow_Migraine_20140811_002937.xml
(8.03 KiB) Downloaded 645 times

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Script issue

Post by Martin » 12 Aug 2014 16:02

Hi Sam,

You are using Multi Choice in the dialog so the user could select multiple values. I did not expect that and I'm not sure how you want to handle the situation when a user selects "No" and "2 Days" at the same time.
You could switch the type of the input dialog to Single Choice or Single Choice Menu and change the script to time = (index+1)+"d";

Regards,
Martin

sambarlick
Posts: 96
Joined: 27 Jul 2014 10:40

Re: Script issue

Post by sambarlick » 12 Aug 2014 21:55

Thanks Martin,

I can't believe i missed that lol, it makes sense now. No wonder it didn't work.

I then realised i needed a condition at the start to see if the flow was still executing so the flow didn't execute again whilst the sleep was active.

Thanks again!
Sam

Post Reply