How to re-arrange a string variable in Flow Designer

AEterni
Mega Guru

Dear All,

  • I am handling an inbound email via Flow Designer
  • I set a variable called "EndDate" in flow designer
  • This variable is a string. I use the variable to parse a date which is in the email body
  • The parsed variable has this format: DD/MM/YYYY (for example 19/02/2023)
  • I need to use this variable to populate a "Date and Time" field in the sc_req_item table
  • Unfortunately, the field takes only dates with this format: YYYY-MM-DD (for example 2023-02-19)
  • To overcome it, I created a new variable called "EndDateRearranged" 
  • I wrote this piece of code to re-arrange the date, but it doesn't work.

 

// Access the input date Flow variable
var enddate = current.enddate;

// Split the input string by "/"
var dateComponents = enddate.split("/");

// Rearrange the components in the desired order
var enddaterearranged = dateComponents[2] + "-" + dateComponents[1] + "-" + dateComponents[0];

// Set the rearranged date value to an output Flow variable
current.enddaterearranged = enddaterearranged;

 

Just for clarity, this is how the flow looks like.

In the "Action 2" I set the "EndDate" variable and in "Action 3" I set the EndDateRearranged

 

AEterni_0-1692971469454.png

Attached is the error trace.

 

Can you please help?

6 REPLIES 6

AEterni
Mega Guru

Dear All,

 

I could not figure out how to use the scripts, so I managed to find an alternative solution.

 

Trigger of the flow is "Inbound Email"

Action1: Parse Email Body Text (action can be downloaded here)

Action2: Set Flow Variables. I created two flow variables and both variables are parsed from the email

  • UserName
  • EndDateString

Action3: Submit Catalog Item Request. I then used the "Fuction" option to convert the string to a date. See image below.

 

AEterni_0-1693474054540.png

 

 

@Peter Bodelier 

@Ankur Bawiskar 

Hi @AEterni 

If you can change it from the flow using transform functions is a much better solution then using a script in the action.

I was under the impression you needed to do in the action. The script I provided should have worked there, but maybe I'm overlooking something in your usecase. 
Glad you were able to solve it!


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.