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

To answer your question, it seems to have alphabetized based on the name and not the sys_id


I added the line and it still doesn't order it in the export.



Here's the current email script:


var gr = new GlideRecord("sc_req_item");


gr.addQuery("sys_id", current.sysapproval);


gr.query();


if(gr.next())


  {


  gs.log("CDL: From Email " + gr.number + " sys id is "+ gr.sys_id);


}




var attachLink = '<a style="color: blue; text-decoration: underline;" href="' + gs.getProperty("glide.servlet.uri") + gs.generateURL('sc_req_item', gr.sys_id) + '">' + 'Click here' + '</a>';




//Request Item Intro text table


htmlContent = '<table>';


htmlContent += '<tr><td width="100%"><p class="body_content">Hello ' + current.approver.first_name + ',</p>';


htmlContent += '<p class="body_content">' + current.sysapproval.number + ': Qlik Dashboard AccessAcces has been opened to request access to the dashboards listed below for' + current.sysapproval.variables.requested_for.getDisplayValue() +'.</p>';


htmlContent += '<p class="body_content">You are listed as the approver for one or more of the requested dashboards.   After reviewing the dashboards you are the approver for listed below, please click either the Approve or Reject link to grant or deny access.</p>';


htmlContent += '<p class="body_content">Thank you.</p></td></tr></table>';




//Dashboard Approver table


htmlContent += '<table id="tlist">';


htmlContent += '<tr><th colspan="2" class="body_content" width="90%">Specific Dashboards Requested</th></tr>';


htmlContent += '<tr><th class="body_content" width="45%">Dashboard Name</th><th class="body_content" width="45%">Access Approved By</th></tr>';


//Build Dashboard Approver rows


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


var list = qlikBoards.split(',');


for (var i = 0; i < list.length; i++) {


  var db = new GlideRecord('u_qlik_dashboards');


  db.addQuery("sys_id", list[i]);


  db.orderBy('u_business_owner');


  db.query();


  if (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>';


  }


}


//Close Dashboard Approver table


htmlContent += '</table>';




//Create & Add link to RITM




htmlContent += '<p></p><p class="body_content">To view more information about the Request Item ' + attachLink + '</p>';


template.print(htmlContent);



which produces this:


Screen Shot 2017-11-29 at 12.06.26 PM.png


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


You're the man Nate!



Screen Shot 2017-11-29 at 1.49.45 PM.png