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

Pring Lat 5 records of current logged in user

Chiranjeevi K
Tera Expert

I am sure the below script will print the last 5 records created on the system but am looking to print last 5 records assigned to the logged in user , could anyone please help me with the change on the below script.

var gr = new GlideRecord('incident);
gr.orderByDesc('sys_created_on');
gr.SetLimit(5);
gr.query();
while(gr.next(){
gs.print('incident number: '+gr.number);
}

11 REPLIES 11

Amit Verma
Kilo Patron
Kilo Patron

Hi @Chiranjeevi K 

 

Please use this :

 

var currentUser = gs.getUserID();
var gr = new GlideRecord('incident');
gr.addQuery('caller_id='+currentUser);
gr.orderByDesc('sys_created_on');
gr.SetLimit(5);
gr.query();
while(gr.next()){
gs.print('incident number: '+gr.number);
}

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

@Amit Verma  Thanks for the response but this is not working , could you please provide any other idea to achieve the same.

Hi @Chiranjeevi K 

 

Can you please let me know where you are running this script ? Also, any errors being thrown when you run this ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

var inc = new GlideRecord('incident');
inc.addQuery('priority', 1)
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
inc.query();
while(inc.next()) {
    gs.print(inc.number);
}