Application Delivery Management
Application Modernization & Connectivity
CyberRes
IT Operations Management
20160506000000Z
function toDate(str) {
//convert an LDAP date string into a Date object
try
{
str = str '';
var year = str.substring(0, 4);
var month = str.substring(4, 6);
var day = str.substring(6, 8);
var hour = str.substring(8, 10);
var minute = str.substring(10, 12);
var second = str.substring(12, 14);
var _date = new Date();
// Set date parts
_date.setFullYear(year);
_date.setMonth(month-1);
_date.setDate(day);
_date.setHours(hour);
_date.setMinutes(minute);
_date.setSeconds(second);
// Return the date object
return _date;
}
catch ( e ) {
alert( 'Error: ' e.description);
return new Date();
}
Kludgy, but reliable and effective.
It would be lovely to just pass in the resulting ECMAscript Date object into the setValues() method of the field object but alas it is not to be. To set the value on that object you must convert it to another string format: “MM/dd/yyyy”. I have another method to do that (a much betterer one that I wrote rather than the toDate() above that I borrowed):
function toMDYYYY(d)
{
return d.toString("MM/dd/yyyy");
}
Now really you don’t need a function for this, you could call the method on the object directly, but I personally prefer to build a function library so I don’t have to exercise all those extra neurons to reinvent the wheel each time I build a PRD.
The importance of a Date object in the middle of this is that you also might want to perform some sort of math before setting the control. A common use case is that you want the default date to be three months in the future so that a non-employee gets an expiring account automagically.
EXPIRATION = 90;
function setExpirationDate(field)
{
var s = new Date().getTime();
s = s EXPIRATION * 1000 * 24 * 60 * 60; // add n days to today
field.setValues( toMDYYYY(new Date(s)));
return s;
}
2018-05-03 11:45:22,914 [ERROR] LogEvent [RBPM] [Workflow_Error] Initiated by cn=UAAdmin,o=acme, Error Message: Attempt to set value on Data item [LoginExpirationTime2] using incorrect type; expecting [date] got [JavaException: java.text.ParseException: Unparseable date: "20180430200000000-0400"].., Process ID: 5979062fa75948338e0d9e77fec42cb3, Process Name:cn=UserAdministration,cn=RequestDefs,cn=AppConfig,cn=UserApp,cn=IDV,ou=IDM,ou=services,o=acme:739, Activity: Activity1, Recipient: cn=UAAdmin,o=acme
20180430200000000-0400
function workflowToJavaDate(data)
{
if (null == data) return null;
var workflowFormat = new java.text.SimpleDateFormat("yyyyMMddhhmmssSSSZ");
try
{
var tempDate = workflowFormat.parse(data);
}
catch (err)
{
System.out.println(err.toString());
return null;
}
return tempDate;
};
workflowToJavaDate(flowdata.get('start/request_form/PasswordExpirationTime'))
Top Comments