Custom widget server script to return values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 12:24 AM - edited 10-21-2022 12:39 AM
Hello All,
I have a custom widget to display a list of returned values.
However the values are repetitive
Also, the requirement is to return first 2 strings of the CI so I have the code ready but need help in tweaking the same in order to get the list right.
Scripts as follows:
HTML
<div class="modal" id="myModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">CIs</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div><div class="container"></div>
<div class="modal-body">
<ul class="list-group result-container">
<li ng-repeat="inc in data.incident">
<a href ng-click="c.openPopUp(inc.sys_id)">{{inc.ci}}</a>
</li>
</ul>
</div>
<div class="modal-footer">
<button type="button" ng-click="CloseModalPopup();">Close</button>
</div>
</div>
</div>
</div>
Server
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.incident=[];
data.user = gs.getUserID();
data.user = gs.getUserID();
var gruser_list1 = new GlideRecord('u_authorized_approver');
gruser_list1.addQuery('u_user',data.user);
gruser_list1.addQuery('u_authorized_approver','true');
gruser_list1.query();
var results = [];
while(gruser_list1.next())
{
var inc = {};
inc.ci = gruser_list1.getDisplayValue('u_ci');
inc = inc.ci.substring(inc.ci.IndexOf("-"),inc.ci.lastIndexOf("-")).trim();
results = inc.split("-")[0].trim() + " "+ inc.split("-")[1].trim();
results.push(inc);
}
data.incident = results.reduce(function(acc,curr,idx){ if(acc.used.indexOf(curr.ci) == -1){ acc.used.push(curr.ci); acc.incs.push(curr) } return acc},{"used":[],"incs":[]}).incs
$sp.log(data.incident);
})();
On the above script
inc.ci = gruser_list1.getDisplayValue('u_ci'); // --> this will display the CI but output will be as follows
Expected output is (only once and not two entries.)
ABC - DHL App
ABC - ORA App
Also the text should be trimmed - I get the expected result but need help with removing duplicate values and pass on to HTML side
inc = inc.ci.substring(inc.ci.IndexOf("-"),inc.ci.lastIndexOf("-")).trim();
results = inc.split("-")[0].trim() + " "+ inc.split("-")[1].trim();
results.push(inc);
@Community Alums @Ankur Bawiskar @Mark Roethof @Chuck Tomasi @Mark Radonic @Pradeep Sharma
TIA