Use of GlideDateTime in eval script of a pattern

thomasbueck
Giga Contributor

Hi,

 

I need to transform timestamps into dates.

I try to use GlideDateTime in an EVAL script during table transformation, but I'm always getting an error.

 

Does anyone know, if it's in general supported, I couldn't find it documented and in the EVAL script examples kb article is no reference/ use of GlideDateTime.

 

Thanks for your support in advance

 

Thomas

1 ACCEPTED SOLUTION

SK Chand Basha
Tera Sage

Hi @thomasbueck 

Glide APIs like GlideDateTime, GlideRecord, Will not work inside eval javascript


Please refer this below KB to learn more about the Eval Scripts in patterns 
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0647736

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0597728

SKChandBasha_0-1778221073695.png

Output: 

SKChandBasha_1-1778221126189.png

 

Type EVAL( and Click on Pencil Icon to write the code!

var timestamp = '1715146200000';

var dt = new Date(parseInt(timestamp));

var output =
dt.getFullYear() + '-' +
('0' + (dt.getMonth()+1)).slice(-2) + '-' +
('0' + dt.getDate()).slice(-2) + ' ' +
('0' + dt.getHours()).slice(-2) + ':' +
('0' + dt.getMinutes()).slice(-2) + ':' +
('0' + dt.getSeconds()).slice(-2);

output;

 

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@thomasbueck 

share your script here

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

thomasbueck
Giga Contributor

That's the script:

set_field {
field_name = "first_hit"
value = eval {"javascript: var intValue= ${panorama_firewall_policies[].first_hit};
intValue=intValue*1000; 
var gdt = new GlideDateTime();
var rtrn = gdt.setValue(intValue);
rtrn;"}
}

SK Chand Basha
Tera Sage

Hi @thomasbueck 

Glide APIs like GlideDateTime, GlideRecord, Will not work inside eval javascript


Please refer this below KB to learn more about the Eval Scripts in patterns 
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0647736

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0597728

SKChandBasha_0-1778221073695.png

Output: 

SKChandBasha_1-1778221126189.png

 

Type EVAL( and Click on Pencil Icon to write the code!

var timestamp = '1715146200000';

var dt = new Date(parseInt(timestamp));

var output =
dt.getFullYear() + '-' +
('0' + (dt.getMonth()+1)).slice(-2) + '-' +
('0' + dt.getDate()).slice(-2) + ' ' +
('0' + dt.getHours()).slice(-2) + ':' +
('0' + dt.getMinutes()).slice(-2) + ':' +
('0' + dt.getSeconds()).slice(-2);

output;

 

thomasbueck
Giga Contributor

@SK Chand Basha Thanks for confirmation - I assumed it, but it's nowhere really clearly outlined.
I'll test your solution next time, as for now I have created a pre processing script and this worked as well.
Thanks again I appreciate your effort and willing to help.