Using script in widget filter

JJG
Kilo Guru

Hello,

I have a service portal page with a 'data table from instance definition' widget. It displays records from my 'hours logged' table. I need to use a script to filter the records that it shows, however, I am getting a strange result.

Filter Script:

javascript:var name = name_of_employee;
var date = date;
var getStart = new GlideRecord('x_utsll_time_manag_time_management');
getStart.addQuery('name_of_employee', name);
getStart.query();
if(getStart.next()){
var start = getStart.pay_period_start
};
date > start; //Only records that are after the getStart.pay_period_start date should be shown
name_of_employee=javascript:gs.getUserDisplayName(); //Only records that match the currently logged in user name

 

find_real_file.png

 

RESULT:

find_real_file.png

 

1 ACCEPTED SOLUTION

Both javascript statements are valid. So if your name_of_employee is a string field and not a reference, and if pay period end is Date field and not Date/Time, then this looks good.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

5 REPLIES 5

Indrajit
Mega Guru

Hey JJG,

 

I think the filter in widget that you are showing is not for scripting purpose these are for the encoded query like active=true. so try encode query to fulfill your displays records from 'hours logged' table.

 

Mark Correct and Helpful if it useful.

Regards,

Indrajit.