I want to create an array type variable for use in a pipeline, but don’t know how to do it.
I want to store this month through December in an array type variable.
For example,
I want to create the following variables in the pipeline to be executed this month;
["07","08","09","10","11","12"]
Also, next month is like this;
["08","09","10","11","12"]
Is there any way to create this variable using Synapse’s pipeline function?
Any answer would be helped.
Thank you.
2
Answers
You can use
for-each activity
andappend variable activity
inside that to create an array variable with values from the current month to December in Synapse pipeline.This activity sets the value of the
StartValue
variable to the current month. It uses the substring function to extract the month from the UTC time and sets it as the value of the variable.Expression:
@substring(utcnow(),5,2)
.This activity sets the value of the TotalIterationValue variable to the number of months left in the year. It uses the sub function to subtract the current month from 13 (the total number of months in a year) and sets it as the value of the variable.
Expression:
@string(sub(13,int(variables('StartValue'))))
Expression in items:
@range(0, int(variables('TotalIterationValue')))
Expression for
Array_variable
:@add(int(variables('StartValue')),item())
This activity loops through a range of numbers from 0 to the value of
TotalIterationValue
and appends the corresponding month to the Array_variable variable. It uses the add function to add the current iteration number to the StartValue variable and sets it as the value of the Array_variable variable.Array_variable
will have the values from current month to December.Adding to Aswin’s approach, as an alternate , you can try this as well :
Create these string variables:
FindCurrentMonth
month
TempVar
Create these Array variables:
appendvariable
finaloutput
@substring(formatDateTime(utcnow(),'yyyy-MM-dd'),5,2)
@equals(variables('TempVar'),'12')
@variables('FindCurrentMonth')
@variables('TempVar')
@{add(int(variables('TempVar')),1)}
@variables('appendvariable')