Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help in scoppped application script for setting the date/time field value.

Community Alums
Not applicable

Hi, 
I have created the below script to set some date/time field values present on the process task (scopped application) table, which extends from the table which is in global scope. 

I am getting below error if I run this in Background script with scope application.

"Background message, type:error, message: Use of Packages calls is not permitted in scoped applications"

var vari_start_date = '';
var p_task = new GlideRecord('x_awin2_integrate_process_task');
p_task.get('0219e240dbff634445f4550a4896191d');
p_task.query();
if(p_task.next()){
vari_start_date = p_task.parent.variables.u_start_date + ' 08:00:00';

var est = Packages.java.util.TimeZone.getTimeZone('US/Eastern');
var pst = Packages.java.util.TimeZone.getTimeZone('UK/Greenwich');
var estGdt = new GlideDateTime();
estGdt.setTZ(est);

var pstGdt = new GlideDateTime();
pstGdt.setTZ(pst);

estGdt.setValue(vari_start_date);

pstGdt.setValue(estGdt);
pstGdt.addSeconds(18000); // add 5 hours

p_task.new_hire_start_date = pstGdt;
p_task.update();
}

can anyone suggest me how to fix this issue. Thank You!

 

Regards,

Ganesh

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

if your task is to convert timezone from US/Eastern to UK/GMT or UTC then no need of package call

check this script will work in scoped app as well and global

Enhance it as per your requirement

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)

gs.info("UTC time:-> " + new GlideDateTime());
gs.info("Converted Time in IST:> " + gdtConvertedDateTime);

Output:

AnkurBawiskar_0-1673333862868.png

 

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

if your task is to convert timezone from US/Eastern to UK/GMT or UTC then no need of package call

check this script will work in scoped app as well and global

Enhance it as per your requirement

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)

gs.info("UTC time:-> " + new GlideDateTime());
gs.info("Converted Time in IST:> " + gdtConvertedDateTime);

Output:

AnkurBawiskar_0-1673333862868.png

 

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