Microsoft Power Automate Switch case - switch-statement

So what I'm trying to replicate is the following,
string str = GetInput from Form();
switch (str)
{
case "1":
case "1 week":
assign variable = 1
Insert variable to excel column
break;
case "2":
case "2 weeks":
assign variable = 3
Insert variable to excel column
case "4":
case "4 weeks":
assign variable = 4
Insert variable to excel column
default:
assign variable = 0
Insert variable to excel column
break;
}
Currently, my flow is similar to the following diagram
Flow
When a new response is submitted
Get response details
Create item action (Run the above switch case condition using a power automate -
functions)

You are using an Apply for Each control in your flow which is equivalent to a For loop in normal programming language. You need to use Switch control for your problem as shown in image below. I have used a sample string parameter to show the usage of switch statement, but if your data is coming from an array you can apply Switch inside Apply for Each loop.
Read this article for step by step guide.

Related

How to make custom references in an Excel row with specific rules ? with VBA or Excel formula

I Want to customise automatically in Excel a Reference number according to the content of the line it is representing.
I have a table for test procedure that looks like this :
Ref
Action
Check
A 001
Name of the Action to perform
Empty if it is an Action
C 001
Empty if it is a Check
Name of the Check to perform
C 002
Empty if it is a Check
Name of the Check to perform
C 003
Empty if it is a Check
Name of the Check to perform
A 002
Name of the Action to perform
Empty if it is an Action
The logic would be the following:
To iterate separately references starting with A and the ones starting with C depending on the type of procedure, that is to say whether the name of the procedure is in Action Column or Check Column.
I would like to implement an algorithm like this, or a formula that does the same thing :
For line in TABLE1 :
if ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Action = Ref_Action + 1
Ref_Code = "A" + Ref_Action
elif ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Check = Ref_Check + 1
Ref_Code = "C"+ Ref_Check
else raise error : "a procedure shall be either an action or a Procedure"
TABLE1[line,Ref] = Ref_Code
(It is not a code language, just my way of representing the algorithm, I hope it is readable.)
Unfortunately, I have no experience in VBA and I couldn't find a way to write an appropriate formula. Or maybe there is another way ?
Thank you,
Gautier

Using custom table to feed drop-down list datasource

Let's assume that I have Custom Table named Possible URL target parameters with code name xyz.PossibleTargets with 2 columns:
Explanation and Value.
How to feed drop-down field on page type with data to have Value (from table) as Value and Explanation as name in drop-down?
What I already tried and it is not working:
Generate value;name pairs divided by newline and place it as List of options:
z = ""; foreach (x in CMSContext.Current.GlobalObjects.CustomTables["xyz.PossibleTargets"].Items) {z += x.GetValue("Value"); z +=";"; z += x.GetValue("Explanation"); z += "\n" }; return z;
Validator do no allow me to do such trick.
Set option Macro expression and provide enumerable object:
CMSContext.Current.GlobalObjects.CustomTables["xyz.PossibleTargets"].Items
In Item transformation: {%Explanation%} and in Value column {%TargetValue%}.
This do not work also.
Dropdown configuration
How to do this correctly? Documentation and hints on the fields are not helpful.
Kentico v11.0.26
I think that you should do it without marking field as a macro. Just type there the macro. Take a look on screen
No need to use a macro, use straight SQL, using a macro only complicates what appears to be a simple dropdown list.
SELECT '', '-- select one --' AS Explanation
UNION
SELECT TargetValue, Explanation
FROM xyz_PossibleTargets -- make sure to use the correct table name
ORDER BY ExplanationText
This should populate exactly what you're looking for without the complication of a macro.

NetSuite Case when statement on joined

I'm new to writing case statements in NetSuite and would appreciate any input with this. I'm trying to create following statement within item search, but receiving invalid expression error.
CASE WHEN {transaction.status} = "Purchase Order:Pending Receipt" THEN {transaction.expectedreceiptdate} end
CASE WHEN {transaction.status} = 'Pending Receipt' THEN {transaction.expectedreceiptdate} end
Note that you need to use single quotes in SQL statements, and you can't specify the transaction type as part of the status condition. To work araound this, you could include the transaction type in the criteria, or add another condition within the CASE statement:
CASE WHEN {transaction.status} = 'Pending Receipt' AND {transaction.type} = 'Purchase Order' THEN {transaction.expectedreceiptdate} end

Lua: Parsing and Manipulating Input with Loops - Looking for Guidance

I am currently attempting to parse data that is sent from an outside source serially. An example is as such:
DATA|0|4|7x5|1|25|174-24|7x5|1|17|TERW|7x5|1|9|08MN|7x5|1|1|_
This data can come in many different lengths, but the first few pieces are all the same. Each "piece" originally comes in with CRLF after, so I've replaced them with string.gsub(input,"\r\n","|") so that is why my input looks the way it does.
The part I would like to parse is:
4|7x5|1|25|174-24|7x5|1|17|TERW|7x5|1|9|08MN|7x5|1|1|_
The "4" tells me that there will be four lines total to create this file. I'm using this as a means to set the amount of passes in the loop.
The 7x5 is the font height.
The 1 is the xpos.
The 25 is the ypos.
The variable data (172-24 in this case) is the text at these parameters.
As you can see, it should continue to loop this pattern throughout the input string received. Now the "4" can actually be any variable > 0; with each number equaling a set of four variables to capture.
Here is what I have so far. Please excuse the loop variable, start variable, and print commands. I'm using Linux to run this function to try to troubleshoot.
function loop_input(input)
var = tonumber(string.match(val, "DATA|0|(%d*).*"))
loop = string.match(val, "DATA|0|")
start = string.match(val, loop.."(%d*)|.*")
for obj = 1, var do
for i = 1, 4 do
if i == 1 then
i = "font" -- want the first group to be set to font
elseif i == 2 then
i = "xpos" -- want the second group to be set to xpos
elseif i == 3 then
i = "ypos" -- want the third group to be set to ypos
else
i = "txt" -- want the fourth group to be set to text
end
obj = font..xpos..ypos..txt
--print (i)
end
objects = objects..obj -- concatenate newly created obj variables with each pass
end
end
val = "DATA|0|4|7x5|1|25|174-24|7x5|1|17|TERW|7x5|1|9|08MN|7x5|1|1|_"
print(loop_input(val))
Ideally, I want to create a loop that, depending on the var variable, will plug in the captured variables between the pipe deliminators and then I can use them freely as I wish. When trying to troubleshoot with parenthesis around my four variables (like I have above), I receive the full list of four variables four times in a row. Now I'm having difficulty actually cycling through the input string and actually grabbing them out as the loop moves down the data string. I was thinking that using the pipes as a means to delineate variables from one another would help. Am I wrong? If it doesn't matter and I can keep the [/r/n]+ instead of each "|" then I am definitely all for that.
I've searched around and found some threads that I thought would help but I'm not sure if tables or splitting the inputs would be advisable. Like these threads:
Setting a variable in a for loop (with temporary variable) Lua
How do I make a dynamic variable name in Lua?
Most efficient way to parse a file in Lua
I'm fairly new to programming and trying to teach myself. So please excuse my beginner thread. I have both the "Lua Reference Manual" and "Programming in Lua" books in paperback which is how I've tried to mock my function(s) off of. But I'm having a problem making the connection.
I thank you all for any input or guidance you can offer!
Cheers.
Try this:
val = "DATA|0|4|7x5|1|25|174-24|7x5|1|17|TERW|7x5|1|9|08MN|7x5|1|1|_"
val = val .. "|"
data = val:match("DATA|0|%d+|(.*)$")
for fh,xpos,ypos,text in data:gmatch("(.-)|(.-)|(.-)|(.-)|") do
print(fh,xpos,ypos,text)
end

Nesting OR statements within AND statements using Funnelback query parameters

I'm trying to insert OR statements within some AND statements on my search and am having trouble nailing down the operators I need to use.
What I'm essentially trying to do is state the following (cue the pseudo)
query = "nematode" && (meta_M == "North" || meta_M == "South") && (meta_N == "Category value 1" || meta_N == "Category value 2")
My attempts seem to have been generating wide OR statements which inflates my initial query for nematode (425 results) into 1,000+ results instead of reducing it to a sub-set of the original results.
I've consulted http://docs.funnelback.com/12.0/query_operator.html but just need that final push.
Funnelback's default operator is and, and the mechanism for specifying or (in the underlying query syntax) is to wrap the or options in square brackets. What I think you want to end up with is the following query.
nematode M:[North South] N:["Category value 1" "Category value 2"]
It looks like you're trying to do that with the query broken down into CGI parameters though. Does...
query=nematode&meta_M=%5BNorth%20South%5D&meta_N=%5B%22Category%20value%201%22%20%22Category%20value%202%22%5D%20
# Note:
# meta_M decodes to [North South]
# meta_N decodes to ["Category value 1" "Category value 2"]
...cover what you need, or must each of the meta_M and meta_N values be in separate CGI parameters?

Resources