Convert GlideDate to LDAP/AD Date

Michael M1
Giga Expert

I have an Orchestration workflow that wants to see the AD user account expiration in a particular format, but not sure what microsoft is looking for...

I am doing this in my workflow:

var gdt = new GlideDateTime(expiry);
gdt.addDaysUTC(extend);
workflow.scratchpad.extend_date = gdt.getDate();

If I log/print the workflow.scratchpad.extend_date I can see "2019-02-01"

When I send this to AD to update the user accountExpires field it changes to:  1601-01-01

Is there a way to convert to microsoft time? 

1 ACCEPTED SOLUTION

Michael M1
Giga Expert

So after banging my head on the wall and then finding some code to do the reverse of what I want for Python (convert MS to UNIX) - I got this to work in my workflow...

 

Objective: Add days to AD accountExpires attribute to extend valid account dates.

 

//Calculate expires date
var gdt = new GlideDateTime(expiry);
gdt.addDaysUTC(extend);

//Here I convert GD to AD date

var gdt2 = new GlideDateTime(gdt);
var gdt_num = gdt.getNumericValue() * 10000;
var gdt_ms = gdt_num + 116444736000000000;
gdt2.setNumericValue(gdt_ms);
//

workflow.scratchpad.extend_date = gdt2.getNumericValue(); //pass to Orchestration

It can be cleaned up and made more efficient but this way shows it off better. 

Next, I will probably try and create a script include and put it in dtUtils...If I get a chance 🙂 

 

View solution in original post

8 REPLIES 8

It is helpful but I want to go in the other direction. 

I may have to look at the dtutils script include.

ryan_pope
Mega Guru

Have you tried something like workflow.scratchpad.extend_date.getDisplayValue() ?

SN might be printing a user-friendly date when in the system, but passing along a value that might not be parseable by AD. The .getDisplayValue() should force the return of a string value that AD should be able to ingest.

 

Thanks - I will try this.

I only tried .getNumericValue() so far.