Expand my Community achievements bar.

SOLVED

Add dynamic value in update activity - example 'Data from March 2025'

Avatar

Level 2

Hello

 

I am trying to find a solution to update Month name ( Jan, Feb, March) and year value (2025) dynamically in an update activity. The value should look like "Data from March 2025"

The Month name should be starting from next month. For example, If I run the workflow in Jan, then the month value should be FEB.

Tried using "'Data from '+Month(AddMonths(formatDate(GetDate(), '%B'), 1))+' '+Year(GetDate())" but it is giving error 
 XTK-170016 You are not authorized to use SQL expressions. 'formatDate' cannot be processed.

Similar to above requirement, I am also trying to add dynamic values in two fields lets say startDate and endDate.
startDate should be from 1st of next month when the workflow executes.

endDate should be last date of next month from when the workflow executes.

if the workflow executes in Feb, startDate would be 1/3/2025 and endDate would be 31/3/2025.

 

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sharma_nik ,

Place an enrichment activity > advanced tab > add below script in initialization script,

//To get Next Month's First Date
var date1 = new Date(); 
date1.setMonth(date1.getMonth() + 1); 
vars.NextMonthFirstDate = '01/'+formatDate(date1, "%2M/%4Y"); 
 
//To get Next Month's Last Date
var date2 = new Date(); 
date2.setMonth(date2.getMonth() + 2); 
vars.twoMonthString = formatDate(date2, "%4Y-%2M")+'-01T00:00:00';
var twoMonthDate = new Date(vars.twoMonthString);
twoMonthDate.setDate(twoMonthDate.getDate() - 1);
vars.NextMonthLastDate = formatDate(twoMonthDate, "%2D/%2M/%4Y");

//Fetch Next Month
var date3 = new Date(); 
date3.setMonth(date3.getMonth() + 1); 
vars.NextMonthString = 'Data from '+formatDate(date3, "%Bl %4Y");
logInfo("Date: "+vars.NextMonthString);

In Enrichment > add data > add the below expressions in output columns,

$(vars/@NextMonthFirstDate)
$(vars/@NextMonthLastDate)
$(vars/@NextMonthString)

ParthaSarathy_0-1738586102017.png

 

Result:

ParthaSarathy_1-1738586139019.png

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @sharma_nik ,

Place an enrichment activity > advanced tab > add below script in initialization script,

//To get Next Month's First Date
var date1 = new Date(); 
date1.setMonth(date1.getMonth() + 1); 
vars.NextMonthFirstDate = '01/'+formatDate(date1, "%2M/%4Y"); 
 
//To get Next Month's Last Date
var date2 = new Date(); 
date2.setMonth(date2.getMonth() + 2); 
vars.twoMonthString = formatDate(date2, "%4Y-%2M")+'-01T00:00:00';
var twoMonthDate = new Date(vars.twoMonthString);
twoMonthDate.setDate(twoMonthDate.getDate() - 1);
vars.NextMonthLastDate = formatDate(twoMonthDate, "%2D/%2M/%4Y");

//Fetch Next Month
var date3 = new Date(); 
date3.setMonth(date3.getMonth() + 1); 
vars.NextMonthString = 'Data from '+formatDate(date3, "%Bl %4Y");
logInfo("Date: "+vars.NextMonthString);

In Enrichment > add data > add the below expressions in output columns,

$(vars/@NextMonthFirstDate)
$(vars/@NextMonthLastDate)
$(vars/@NextMonthString)

ParthaSarathy_0-1738586102017.png

 

Result:

ParthaSarathy_1-1738586139019.png

Avatar

Level 2

Thank you so much Partha for your response. It helped a lot.