Skip to main content

I have a custom attribute that is a Date/Time field:

 

I am trying to pre-populate the current Date/Time in this field when a new record is created. I am familiar with the process enrichment BPA flow, and I have identified the correct projection to tie into. 

I am also inserting the current user that triggers the BPA in a different field, so i know my flow is working correctly. However, when I try to insert the current date/time, i receive an error. 

 

This is my flow:

 

The code in my “Get Current DateTime” node: 

var currentDate = new Date();
execution.setVariable("Cf_Pcx_Datetime", currentDate);

When triggered, I receive this error:

 

I have also tried the following code and received the same error:

var currentDate = new Date();
var isoDate = currentDate.toISOString();
execution.setVariable("Cf_Pcx_Datetime", isoDate );

I have also tried to hardcode an ISO string and supply that variable, same error. 

For reference, I am on 24R2.5. What am I missing? Thanks in advance!

Hi ​@mdezzi
 

Currently, the BPA workflow engine supports the following DATETIME formats:

  • yyyy-MM-dd-HH.mm.ss (2023-09-21-07.04.39)
  • yyyy-MM-dd-HH.mm.ss.SSSSSSS (2023-09-22-08.04.39.0000000)

https://docs.ifs.com/techdocs/24r2/040_tailoring/500_business_process_automation/250_workflow_faq/

So, in order to set the default value correctly, you can use the following script to format the date and set it as an execution variable:

 

var SimpleDateFormat = Java.type("java.text.SimpleDateFormat");
var Date = Java.type("java.util.Date");

var currentDate = new Date();
var sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");

var formattedDate = sdf.format(currentDate);

execution.setVariable("Cf_Pcx_Datetime", formattedDate);

 

Thanks 
/Yohan


Hi. Workflow needs datetimes in specific formats

  • yyyy-MM-dd-HH.mm.ss (2023-09-21-07.04.39)

  • yyyy-MM-dd-HH.mm.ss.SSSSSSS (2023-09-22-08.04.39.0000000)

This is a sample barebones script to format the current date. Improve as needed. Try if this works.

 

    var now = new Date();
    var isoString = now.toISOString();
    var datePart = isoString.substring(0, 10);
    var timePart = isoString.substring(11, 19).replace(/:/g, '.');

// yyyy-MM-dd-HH.mm.ss
    var datetime = datePart + '-' + timePart ;

execution.setVariable("Cf_Pcx_Datetime", datetime );


Thank you ​@yohan and ​@Buddhi Gunasekara, both these answers work. One question though, it appears the scripts are returning the current UTC time (in this case 12:25pm) and our server (and business) is located in EST. Is it possible to either apply a time zone, or simply subtract 4 hours from the time? 


@mdezzi Both options work, but I feel like applying the time zone is the better way to go, since it also handles daylight saving automatically.

sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));


@yohan I agree, timezone is the way to go. 

When i drop that line after declaring sdf, i get a debug error. 

My code:

var SimpleDateFormat = Java.type("java.text.SimpleDateFormat");
var Date = Java.type("java.util.Date");
var currentDate = new Date();
var sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));
var formattedDate = sdf.format(currentDate);

execution.setVariable("Cf_Pcx_Datetime", formattedDate);

The error:

 

 

think it wants me to declare the TimeZone ahead of time (i’m in over my head when it comes to Javascript and Oracle).

I updated my code to the following and it seems to work as expected:

var SimpleDateFormat = Java.type("java.text.SimpleDateFormat");
var Date = Java.type("java.util.Date");
var TimeZone = Java.type("java.util.TimeZone")
var currentDate = new Date();
var sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));
var formattedDate = sdf.format(currentDate);

execution.setVariable("Cf_Pcx_Datetime", formattedDate);

Appreciate all the help!!


Reply