UI Page query using array

DoDo labs___
Mega Sage

 

I would like to pass change requests in an array to a UI Page using UI Action and display only those changes.
The current HTML script displays all changes.
How should i modify the HTML script to achieve this?
 
 
UI Action script:
 
function openChangeRequestList_NoParent(){
 
    var lista = [];
 
    var gr = new GlideRecord('problem');
    gr.addQuery('sys_id', g_form.getUniqueValue());
    gr.query();
    if (gr.next())
        {
            lista = gr.u_change_list.split(",");
        }
 
    var dialog = new GlideDialogWindow('FIG_problem_remove_change'); 
    dialog.setTitle('Remove Change Request');
    dialog.setSize(650, 600);
    g_scratchpad.info = g_form.getUniqueValue();
    dialog.setPreference('sysparm_number', lista);
    dialog.render();
 
}
 
UI Page HTML 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">
     <g:ui_form>
<table>
<tr>
                  <td style="width:25%">
<g:form_label>
Select Change Request: 
        </g:form_label>
                  </td>
  <td style="width:60%">
    <g:ui_reference name="number" id="number" query="user_nameSTARTSWITHa" table="change_request"  />
                   </td>
                </tr>
<tr>
                     <td>
                       <g:dialog_buttons_ok_cancel ok_id="submitData" ok="return continueOK()" ok_type="button" ok_text="${gs.getMessage('Submit')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="return continueCancel()"/>
                    </td>
               </tr>
</table>
</g:ui_form>
</j:jelly>
 
1 ACCEPTED SOLUTION


I have found a solution: I converted the array to a string, and with the numbers of the changes, I also passed the following text to the ui page:
^NQnumberSTARTSWITH

This is how I passed it to the UI page:


<j:set var="jvar_numbers" value="${RP.getWindowProperties().get('Change_Requests')}">
</j:set>
<g:ui_reference name="number" id="number" query="${jvar_numbers}" table="change_request" />

View solution in original post

5 REPLIES 5

Satishkumar B
Giga Sage
Giga Sage

Hi @DoDo labs___ 

 

I noticed a few adjustments and clarifications that can be made to ensure correctness and effectiveness:

Updated UI Page HTML 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">
<g:ui_form>
<table>
<tr>
<td style="width:25%">
<g:form_label>Select Change Request:</g:form_label>
</td>
<td style="width:60%">
<g:ui_reference name="number" id="number" query="active=true^sys_idIN${gs.getList('sysparm_number')}" table="change_request" />
</td>
</tr>
<tr>
<td colspan="2">
<g:dialog_buttons_ok_cancel ok_id="submitData" ok="continueOK()" ok_type="button" ok_text="${gs.getMessage('Submit')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="continueCancel()"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>

Explanation and Adjustments:

1. UI Reference (`<g:ui_reference>`):
- Changed `query="active=true^sys_idIN${request.getParameter('sysparm_number')}"` to `query="active=true^sys_idIN${gs.getList('sysparm_number')}"`.
- Uses `gs.getList('sysparm_number')` to retrieve the comma-separated list of `sys_id` values passed from the UI Action. `gs.getList()` is preferable in this context to handle arrays passed from UI Actions correctly.

2. Dialog Buttons:
- Consolidated the OK and Cancel buttons under `<td colspan="2">` for clarity and proper alignment.

 

Additional Tips:

- Parameter Passing: Ensure that `sysparm_number` is correctly passed as a comma-separated list of `sys_id` values from your UI Action (`dialog.setPreference('sysparm_number', lista)`).

- Testing: Test the UI Action and UI Page integration to verify that only the specified change requests are displayed based on the passed `sysparm_number`.

By implementing these adjustments, the UI Page should correctly display and filter change requests based on the array passed from the UI Action, ensuring the functionality aligns with your requirements.

 

———————————————————-
If my response helps, please mark it as "Accept as Solution" and consider it "helpful."

Thank you for your help! 

Unfortunately the list is now empty. 😞

Hi @DoDo labs___ 

  • Verify Parameter Passing: Confirm that sysparm_number is correctly set in your UI Action using dialog.setPreference('sysparm_number', lista).

  • Check UI Page Query: Ensure you're using gs.getList('sysparm_number') in your UI Page's <g:ui_reference> query attribute to fetch and filter based on sys_id values.

  • Debugging Steps: Log sysparm_number in the UI Page to ensure it's correctly received and contains the expected values. Check for any errors in the browser console or server logs.

  • Direct Query Testing: Validate the generated query (active=true^sys_idIN${gs.getList('sysparm_number')}) directly in your ServiceNow instance to confirm it returns results.

 

--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

 

now the UI Action looks like this:
 
function openChangeRequestList2_NoParent(){
 
    var szoveg = '';
    var lista = [];
 
    var gr = new GlideRecord('problem');
    gr.addQuery('sys_id', g_form.getUniqueValue());
    gr.query();
    if (gr.next())
        {
            szoveg = gr.u_change_list.toString();
        }
 
alert(szoveg);
lista = szoveg.split(",");
alert(lista[1]);
 
 
    var dialog = new GlideDialogWindow('FIG_problem_remove_change'); 
    dialog.setTitle('Remove Change Request');
    dialog.setSize(650, 600);
    g_scratchpad.info = g_form.getUniqueValue();
dialog.setPreference('sysparm_number', lista);
    dialog.render();
 
}

 

As you can see, the  sysparm_number is correctly set in  the UI Action.


the first alert says:

DoDolabs____0-1720163475044.png


the second alert says:

 

DoDolabs____1-1720163719759.png

 

Here is the UI Page HTML:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<table>
<tr>
<td style="width:25%">
<g:form_label>Select Change Request:</g:form_label>
</td>
<td style="width:60%">
<g:ui_reference name="number" id="number" query="sys_idIN${gs.getList('sysparm_number')}" table="change_request" />
</td>
</tr>
<tr>
<td colspan="2">
<g:dialog_buttons_ok_cancel ok_id="submitData" ok="continueOK()" ok_type="button" ok_text="${gs.getMessage('Submit')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="continueCancel()"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
 
But there is nothing in the url after sys_idIN, could this be the problem?
 
DoDolabs____3-1720164500259.png