GetByFormat will not worked in scoped application?

Sathwik1
Tera Expert

I am getting the wrong output after executing the below code.

var gr = new GlideRecord('x_408194_loading_e_scoped_data_table');
gr.query();
if(gr.next()) {
var gettDate = gr.date;
}
gs.info(gettDate);
var gd = new GlideDate(); 
gd.setValue(gettDate);
gs.info(gd.getByFormat('dd-mm-yyyy'));

Output

2022-04-22
22-00-2022
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it works in scope

you have given the wrong format

update as this

var gr = new GlideRecord('x_408194_loading_e_scoped_data_table');
gr.query();
if(gr.next()) {
var gettDate = gr.date;
}
gs.info(gettDate);
var gd = new GlideDate();
gd.setValue(gettDate);
gs.info(gd.getByFormat('dd-MM-yyyy'));

Regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it works in scope

you have given the wrong format

update as this

var gr = new GlideRecord('x_408194_loading_e_scoped_data_table');
gr.query();
if(gr.next()) {
var gettDate = gr.date;
}
gs.info(gettDate);
var gd = new GlideDate();
gd.setValue(gettDate);
gs.info(gd.getByFormat('dd-MM-yyyy'));

Regards
Ankur

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

Community Alums
Not applicable

Hi @Sathwik ,

getByFormat() works in scoped application. Example:

var gd = new GlideDate(); 
gd.setValue('2021-04-21');
gs.info(gd.getByFormat("YYYY-MMM-dd"));

find_real_file.png

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep