Question
Pegasystems Inc.
NZ
Last activity: 1 May 2020 5:12 EDT
Concatenate functions in Expression Builder
Hello,
I am working on a scenario where I need to set a Date Property to the Monday of the current week. So an example, current date is 20200430 (Thursday), I need to find 20200427 (Monday).
I couldn't find a function that does this for me, so I am working with a Data Transformation Expression Builder to get there.
I have identified already a could of functions that can help me:
@(Pega-RULES:DateTime).getCurrentDateStamp() --> returns current date
@DateTime.weekday(20200430) --> returns 5
and then ... I don't know yet, I have to think about that, but the issue I am facing is that I don't know how to link to two.
I tried with local variables:
var x = @(Pega-RULES:DateTime).getCurrentDateStamp() --> generates and error, I don't think it's supported
I tried linking the 2 expressions:
@DateTime.weekday(@(Pega-RULES:DateTime).getCurrentDateStamp() ) --> generates another error
Any suggestions on how can I do what I need?
Cheers.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 1 May 2020 5:11 EDT
Blue Rose Technologies
DE
Also to get Monday of current week you can use below expression.
addToDate(CurrentDateTime(),(2-(weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)))),0,0,0)
Updated: 14 Jun 2021 7:38 EDT
Pegasystems Inc.
IN
Please find the below screenshot to concatenate both the expressions.
Pegasystems Inc.
NZ
Thanks Kanap,
I have a slightly different objective though, and probably 'concatenate' is the wrong word to describe what I want to achieve.
I want to use the output of one function as in input of the other one. In unix I would say 'pipe', not sure if it make sense here. My non-working example is a good example of this:
@DateTime.weekday(@(Pega-RULES:DateTime).getCurrentDateStamp() )
Basically I want to pass the result of @(Pega-RULES:DateTime).getCurrentDateStamp() to @DateTime.weekday()
I hope is clear now.
Cheers.
Blue Rose Technologies
DE
You can try this one,
weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools))
-
Giovanni Vigorelli
Accepted Solution
Updated: 1 May 2020 5:11 EDT
Blue Rose Technologies
DE
Also to get Monday of current week you can use below expression.
addToDate(CurrentDateTime(),(2-(weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)))),0,0,0)
-
Giovanni Vigorelli
Pegasystems Inc.
NZ
Hi Shyju,
Thank you very much! I am getting closer to my final goal, that's awesome.
I have a couple of questions.
1. I don't understand when I have to use a specific Pega syntax, like @(Pega-RULES:DateTime).getCurrentDateStamp() or a (Java I guess) function is enough CurrentDateTime()
2. Is there a way to add logic (IF.. THEN.. or local Varialbles) into the Expression Builder? While your code works like a charm, it's a bit static (I have to know the current day to subtract the exact number of days to get to Monday), with some IF... THEN... and local Variables i can make it dynamic.
Cheers.
Pegasystems Inc.
NZ
I have found the answer to my second question. This is the working Expression for my use case:
if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 1, getCurrentDateStamp(), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 2, addToDate(CurrentDateTime(),-1,0,0,0), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 3, addToDate(CurrentDateTime(),-2,0,0,0), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 4, addToDate(CurrentDateTime(),-3,0,0,0), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 5, addToDate(CurrentDateTime(),-4,0,0,0), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 6, addToDate(CurrentDateTime(),-5,0,0,0), if (weekday(dateStringToBigDecimal(getCurrentDateStamp(),Date,tools)) = 7, addToDate(CurrentDateTime(),-6,0,0,0), addToDate(CurrentDateTime(),-6,0,0,0) ) ) ) ) ) ) )
-
Giovanni Vigorelli
Blue Rose Technologies
DE
Hi,
1. For me it worked with CurrentDateTime() itself in expression builder opened from data transform. I opened expression builder from Data Transform and did browse and added CurrentDateTime(). You can test once whether CurrentDateTime() is working for you and if not change it to @(Pega-RULES:DateTime).getCurrentDateStamp().
2. My code should work for any day. If we run the code on any day, result will be that week Monday. We don't have to do separate if else condition for different days.
Please see screenshot below executing same code today (Friday) and getting result as last Monday. I executed same code yesterday and got result as last Monday.
Pegasystems Inc.
NZ
I understand you code now, much more concise and efficient than the multiple 'if'.
Thanks again for your help.
Cheers.