remove duplicates from the gr records retrieved in ui page

hemali1
Kilo Contributor

I am trying to remove the duplicates from the glide records I retrieve in the UI page. Following is the script:

 

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<html>

<body>

<j:set var="jvar_user_group" value="" />

<g:evaluate var="jvar_pm_project_record" object="true" jelly="true">

var grp = new GlideRecord('sys_user_group');  

grp.addQuery('name', '');  

grp.query();

</g:evaluate>

<j:if test="">

<g:evaluate object="true">  

var wval = new GlideRecord('sys_variable_value');  

wval.addQuery('value','');  

 

wval.query();

 

</g:evaluate>

 

 

<h1><span style="color: #808080;">Group: <br /></span></h1>

 

<table style="height: 168px; width: 567px;" border="1">

<tbody>

<tr style="height: 40px;">

<td style="width: 430px; height: 40px; font-size:20px"><B>Group Name</B></td>

<td style="width: 500px; height: 40px; font-size:20px"><B>Workflow/Catalog Item</B></td>

</tr>

<j:while test="">

<g:evaluate object="true">  

var wact = new GlideRecord('wf_activity');  

wact.addQuery('sys_id','');

wact.query();

</g:evaluate>

<j:while test="">

 

<tr style="height: 43px;">

<td style="width: 430px; height: 43px;"></td>

<td style="width: 500px; height: 43px;"></td>

</tr>

</j:while>

</j:while>

</tbody>

</table>

</j:if>

</body>

</html>

 

 

</j:jelly>

1 ACCEPTED SOLUTION

You have a groupBy in the second example, unnecessary with array building.   In theory, the "gr" parts would work in a script.   I'm not sure how to debug this, but as long as ${wval.document_key} is actually evaluating correctly to a wf_activity sys_id, this should be about what you need.   Do you have read permission on the wf_activity table?   Where is wval coming from?



You need to add a variable name to your evaluate block.


Jelly Tags - ServiceNow Wiki



<g:evaluate var="jvar_gr" object="true">


            var gr = new GlideRecord('wf_activity');


            gr.addQuery('sys_id','${wval.document_key}');


            gr.groupBy('workflow_version');


            gr.query();


            gr;


</g:evaluate>



<j:while test="${jvar_gr.next()}">


                    <tr style="height: 43px;">


                  <td style="width: 430px; height: 43px;">Workflow Name:</td>


                  <td style="width: 500px; height: 43px;">${jvar_gr.workflow_version.name}</td>


                  </tr>


</j:while>


View solution in original post

8 REPLIES 8

andrewpilachows
Kilo Guru

You either use groupBy OR arrays in order to get distinct records.   If you only want a single field from the returned record, use groupBy.



I do not know how to work with jelly currently to know how you would display the records.


I meant I tried both ways, once using group by and the next time using arrays. None of it seems to be working. Display isn't the problem over here


You have a groupBy in the second example, unnecessary with array building.   In theory, the "gr" parts would work in a script.   I'm not sure how to debug this, but as long as ${wval.document_key} is actually evaluating correctly to a wf_activity sys_id, this should be about what you need.   Do you have read permission on the wf_activity table?   Where is wval coming from?



You need to add a variable name to your evaluate block.


Jelly Tags - ServiceNow Wiki



<g:evaluate var="jvar_gr" object="true">


            var gr = new GlideRecord('wf_activity');


            gr.addQuery('sys_id','${wval.document_key}');


            gr.groupBy('workflow_version');


            gr.query();


            gr;


</g:evaluate>



<j:while test="${jvar_gr.next()}">


                    <tr style="height: 43px;">


                  <td style="width: 430px; height: 43px;">Workflow Name:</td>


                  <td style="width: 500px; height: 43px;">${jvar_gr.workflow_version.name}</td>


                  </tr>


</j:while>


shivanipatel
ServiceNow Employee
ServiceNow Employee

Hemali,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png