Sort Array?

conanlloyd
Giga Guru

I freely admit to begging for help from the mighty ctomasi and/or anyone else who can help

I have an email script that, in the approval email, displays the name and approver of dashboards selected in our Qlik Dashboard Access catalog item.   It works fine, but the business has asked for the results to be sorted by approver to make it easier for the approvers to see all the dashboards they are responsible for.   Here's my working script without any kind of sort.:

Screen Shot 2017-11-16 at 6.16.48 PM.png

which produces output like this:

Screen Shot 2017-11-16 at 6.18.31 PM.png

Based on this article by Steve Bell, here is m

Image of my attempt that isn't working:

Screen Shot 2017-11-16 at 6.11.59 PM.png

In case anyone is wondering why I am using images instead of pasting code it's because something in the code keeps breaking the form here, sending it into an endless loop where it says an error prevents saving .

1 ACCEPTED SOLUTION

ahhhh I see what's going on hahaha



change this section:



var qlikBoards = current.sysapproval.variables.qlik_db.toString();  


  var db = new GlideRecord('u_qlik_dashboards');  


  db.addEncodedQuery("sys_idIN"+ qlikBoards );  


  db.orderBy('u_business_owner');  


  db.query();  


  while (db.next()) {  


htmlContent += '<tr><td class="table_content" width="45%" align="left">' + db.u_name.getDisplayValue() + '</td><td width="45%" class="table_content" align="left">' + db.u_business_owner.getDisplayValue() +'</td></tr>';  


  }  



this should also improve performance of the script


View solution in original post

8 REPLIES 8

ruzzty06
Tera Expert

I believe you have error in your 2nd script. from the line


tmpObj.dbName=task.getDisplayValue.....



you have no task variable, should be db.


tmpObj.dbName=db.getDisplayValue.....   so on, replace all tasks with db



and also did you declare taskObjList variable? I can't seem to see your declaration


Nate23
Mega Guru

I would think your original code would suffice just drop in:



db.orderBy('u_business_owner');



after your addQuery


This will sort your query results by the "u_business_owner" field which I am guessing is your approvers? so when you iterate through your GlideRecord object it will already be sorted instead of having to store the information in a variable and sort it yourself.




GlideRecord - ServiceNow Wiki



please use this link quick as the wiki will be retiring on Dec 10th!!!! RIP


will


db.orderBy('u_business_owner');


order it by sys_id or by the name of the owner?


I also want to know if orderby can be used to sort the name.