## Send To Multiplie Statement

All topics on coding 4Dscript in Enterprise Dynamics.
esrk
Posts: 2
Joined: Saturday 11 July, 2020 - 22:47

### Send To Multiplie Statement

Hello, I need help in 4d Script, im doing a project in university.

I have emprical distribution with 8 values, a server where products get the label called "gate" with one of these values 1 to 8, then they go to a multi server and from there they go to 4 different "gates" according their labels. So it is simply products with value 1 and 5 go to output channel 1, with value 2 and 7 to output channel 2, etc. I need a code for sendto field in the multi server, here is what I have but with this only the last statement works, so they go only to the 4th output channel, products with other values stay in the server and dont come out.

do(
If(or(Label([gate],first(c))=1,Label([gate],first(c))=5),1),
If(or(Label([gate],first(c))=2,Label([gate],first(c))=7),2),
If(or(Label([gate],first(c))=3,Label([gate],first(c))=6),3),
If(or(Label([gate],first(c))=4,Label([gate],first(c))=8),4)
)

HarryBunnik
Posts: 340
Joined: Monday 07 February, 2011 - 11:22

### Re: Send To Multiplie Statement

Hi Ersk,

There are a few ways to write something likes this. What you have written is indeed not working, since all if's are at the same level. As a result only the last line of your code is responsible for what is coming out. You should write that more in the shape of an If-else structure:

Code: Select all

``````  If(
Or(
Label([Gate], First(c)) = 1,
Label([Gate], First(c)) = 5
),
{If}
1,
{Else}
If(
Or(
Label([Gate], First(c)) = 2,
Label([Gate], First(c)) = 6
),
{2nd if}
2,
{Else}
If(
.  ...

)
)
)
)
``````
Easier than so many If's nested, is a "WhichIsTrue" statement:

Code: Select all

``````  WhichIsTrue(
Or(
Label([Gate], First(c)) = 1,
Label([Gate], First(c)) = 5
),
Or(
Label([Gate], First(c)) = 2,
Label([Gate], First(c)) = 6
),
Or(
Label([Gate], First(c)) = 3,
Label([Gate], First(c)) = 7
),
Or(
Label([Gate], First(c)) = 4,
Label([Gate], First(c)) = 8
)
)``````
And even easier, when it comes to the length of the code, would be to use a modulus on the label value. This is a bit harder to understand, but makes nice compact code:

Code: Select all

``Mod(Label([gate],first(c)) - 1, 4) + 1``
I hope this helps you further,

Gr. Harry

esrk
Posts: 2
Joined: Saturday 11 July, 2020 - 22:47

### Re: Send To Multiplie Statement

thank you very much, you helped me a lot!