How to convert a string field into a date field.

Raju Singh1
Tera Expert

Hi Experts,

In the User Record, I have a field Termination Date (u_termintion_date) which is a string type. This value is populating from my AD(Active Directory) as a string Value. Screenshot provided below.

I want to convert this value to a Date value and populate the same value in the field Term Date (u_term_date) which is a Date type field.

Termination date values are a random values and every time this value will be changing for different users.

Could you please help me with the code which I need to run in the business Rule After Update.

 

What will be the script used if I use Term Date as a Date/Time Type .

Please find the screen shot below

find_real_file.png

Regards,

Raju Singh

 

 

 

9 REPLIES 9

Hi Vishal,

 

Thank you for the code. However, I think this is an incomplete code as it doesn't deal with my fields which I specified in the example. How shall I assign this code to my field.

 

document.body.innerHTML = dateObject.toString();

 

Could you please provide the full code

Regards,

Raju Singh

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Below is a perfect example to make a string field to a date time field:

 

var date = new GlideDate('u_termintion_date');

 

Thanks,
Ashutosh Munot

Hi Ashutosh,

 

Thank you for your help. I tried your code but it gives me the following error.

 

Error Message

Error running business rule 'Term Date conversion from string to date' on sys_user:Ranjan Choudhary, exception: org.mozilla.javascript.EvaluatorException: Java constructor for "com.glide.glideobject.GlideDate" with arguments "string" not found. (sys_script.11eda442db399f40952dff971d9619af.script; line 4)
 
 
 
Here is my code which I tried
 
 
(function executeRule(current, previous /*null when async*/) {
 
var gr = new GlideRecord("sys_user");
 var date = new GlideDate('u_termination_date');
 gr.u_term_date = date;
 
})(current, previous);

 

HI, 

 

Use this: var date = new GlideDate(current.u_termination_date);

 

Thanks,
Ashutosh

Community Alums
Not applicable
You can use the below code it is working for me on before business rule.
var td = current.requisition_raised_data.toString();
var td1 = new GlideDateTime(td);
current.date = td1;
gr.update();