How to convert a string field into a date field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2018 12:38 AM
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
Regards,
Raju Singh
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2018 02:11 AM
Hi,
Try with below script:
var gr = new GlideRecord("name_of_the_table");
gr.addEncodedQuery("pass_the_required_query");
gr.query();
if(gr.next()){//If to check for one record and if working fine then change it to While
var td = gr.u_termination_date.toString();
var td1 = new GlideDateTime(td);
gr.u_term_date = td1;
gr.update();
}
Regards,
Ram M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2018 12:21 AM
Hi Ram Mohan,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2018 03:26 PM
Hey I tried this option with a situation I have. I need to convert a string to a duration field. In the string I put a time to completion for Knowledge Articles, for example I place a 5 which mean 5 minutes and then I need to convert that in a GlideDuration field. How can I do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2018 02:29 AM
Hi,
try below code:
var dateString = "03/23/2017"; // Oct 23
var dateObject = new Date(dateString);
document.body.innerHTML = dateObject.toString();