Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add year in flow

VSN
Tera Expert

Hi All, I have one requirement to auto create project record when program (parent)was created.

for this process i go with flow designer part, i have created flow.

as a part of new record creation the project description will be combination of parent name (program name ) and start date field year.

example: - parent name is testingcomm and start is is 03/05/2028. then project description will be like " testingcomm 28". 

so my query is how can i get the 2 digit year details in flow?

3 REPLIES 3

Mark Manders
Mega Patron

You need to script your Short Description something like this:

var currentDateTimeStr = gs.nowDateTime();
var glideDateTime = new GlideDateTime(currentDateTimeStr);
var fullYear = glideDateTime.getYearLocalTime();
var yearShort = fullYear.toString().substr(-2);
var desc = fd_data.+the rest of your data pill for the name;
var shortDesc = desc + ' ' + yearShort;
return shortDesc;

Just set a reminder in your calendar that you need to change this flow on December 31st in the year 9999. After that date it will return 3 characters instead of 2.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

dpac_nick
Tera Contributor

If you have name and date field with correct values, you can access them using fd_data object in script part of Description in flow.

Then it just require some splits and splices to reach that particular suffix of year in that particular field. 

 

 

var name = fd_data.trigger.current.field_name.getDispalyValue();
var date_time = fd_data.trigger.current.date_field.getDisplayValue();
var date_split = date_time.split(' ');
var date = date_split[0].split('-');
var year_suffix = date[0].slice(2);
return name + ' ' + year_suffix;

 

 

 

If this works for you, please mark my answer correct or helpful.

@dpac_nick it is almost close to requirement, final result will be like " parent name - FY startdate name ";

example: Testing-FY24