The CreatorCon Call for Content is officially open! Get started here.

How to get the first record by Create Date

carlocsa
Kilo Expert

Hi ServiceNow Gurus!

I am creating a business rule that needs to show the first record created in 'sys_user_grmember' sorted by 'sys_created_on'. Part of the code in my

business rule is:

var grug = new GlideRecord('sys_user_grmember');

grug.addQuery('user', current.user);

grug.addQuery('group.active', true);

grug.addQuery('group.type', 'CONTAINS', itil);

grug.orderByDesc('sys_created_on');

grug.setLimit(1);

grug.query();

I think that what's wrong with the code is the line "grug.orderByDesc('sys_created_on');"

Please help!

Thank you!

Carlo

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Carlo,



Replace line grug.orderByDesc('sys_created_on'); with grug.orderBy('sys_created_on');


View solution in original post

3 REPLIES 3

Shishir Srivast
Mega Sage

can we try itil in quotes in below code?



grug.addQuery('group.type', 'CONTAINS', 'itil');


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Carlo,



Replace line grug.orderByDesc('sys_created_on'); with grug.orderBy('sys_created_on');


Eric Levinson
Tera Contributor

Can this be done in the report designer without scripting? 
I'd like a dashboard visualization to show the oldest  requested item number with the date next to it.  There's no way in filters I can figure out how to show the "Oldest" only.  I have a group set to only show 1 maximum row.
Is there a filter I can enable to just show the oldest row?  Grouping creates a hiearachy and I don't want this.  I want something similar to a TOP[1} by Date function.