Display list of records based on ui action on ui page in workspace

Shubham Gagneja
Tera Guru

Hello,
I am trying to get record details based on my custom table form in workspace. I have 4 fields on my form, last name, first name, gender and dob. If a user enters value, there is a ui action checks the user info from my custom table based on the field value and opens a ui page displaying the records. I created the ui page and i did call it and i can see the ui page as a modal but info is not there. 
Can someone help me with the logic?

13 REPLIES 13

Hello @Shubham Gagneja 

 

Yesss , I just as scripted it in general logic and came up with it. My main focus is on jelly one.

 

However, can you try below 👇 updated scripts - 

 

function openUserInfoPage() {

    var lastName = g_form.getValue('last_name');

    var firstName = g_form.getValue('first_name');

    var gender = g_form.getValue('gender');

    var dob = g_form.getValue('dob');

 

    var url = "/sys_ui_page.do?sys_id=<YOUR_UI_PAGE_SYS_ID>&last_name=" + encodeURIComponent(lastName) +

        "&first_name=" + encodeURIComponent(firstName) +

        "&gender=" + encodeURIComponent(gender) +

        "&dob=" + encodeURIComponent(dob);

 

    var modal = new g_modal({

        title: "User Info",

        url: url,

        size: "lg", // Options: 'sm', 'md', 'lg', 'xl'

    });

 

   

modal.show(); }

 

Jelly script will also be updated in that case, as modal only opens in responsive platform - 

 

Refer below 👇 

 

<g:include src="ui_page_header"/>

 

<g:evaluate>

    var lastName = decodeURIComponent(g_request.getParameter("last_name") || '');

    var firstName = decodeURIComponent(g_request.getParameter("first_name") || '');

    var gender = decodeURIComponent(g_request.getParameter("gender") || '');

    var dob = decodeURIComponent(g_request.getParameter("dob") || '');

 

    var userRecord = new GlideRecord('your_custom_table');

    userRecord.addQuery('last_name', lastName);

    userRecord.addQuery('first_name', firstName);

    userRecord.addQuery('gender', gender);

    userRecord.addQuery('dob', dob);

    userRecord.query();

</g:evaluate>

 

<div class="container">

    <h2>User Information</h2>

    <table class="table table-striped">

        <thead>

            <tr>

                <th>Last Name</th>

                <th>First Name</th>

                <th>Gender</th>

                <th>DOB</th>

            </tr>

        </thead>

        <tbody>

            <g:while var="userRecord.next()">

                <tr>

                    <td>${userRecord.last_name}</td>

                    <td>${userRecord.first_name}</td>

                    <td>${userRecord.gender}</td>

                    <td>${userRecord.dob}</td>

                </tr>

            </g:while>

 

        </tbody>

    </table> </div>

 

Please replace with correct table names everywhere and functions also. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

In your first jelly script

function openUserInfoPage() {
var lastName = g_form.getValue('last_name');
var firstName = g_form.getValue('first_name');
var gender = g_form.getValue('gender');
var dob = g_form.getValue('dob');

var url = "/sys_ui_page.do?sys_id=<YOUR_UI_PAGE_SYS_ID>&last_name=" + encodeURIComponent(lastName) +
"&first_name=" + encodeURIComponent(firstName) +
"&gender=" + encodeURIComponent(gender) +
"&dob=" + encodeURIComponent(dob);

var myDialog = new GlideDialogWindow('<YOUR_UI_PAGE_SYS_ID>');
myDialog.setTitle('User Info');
myDialog.setSize(800, 600);
myDialog.setPreference('last_name', lastName);
myDialog.setPreference('first_name', firstName);
myDialog.setPreference('gender', gender);
myDialog.setPreference('dob', dob);
myDialog.render();
}

Where are you calling url?

@Shubham Gagneja 

seems you are not able to pass values to UI page using g_modal

check this

How to use UI Actions in Workspaces 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar My use case is i want to pass list of records from ui action to ui page. those list of records should come based on the values that i set on the form. If i set last_name, it should query my custom user table and get me records based on that in my ui page. Can you help me with this query?

@Shubham Gagneja 

did you check UI page is able to get the value from g_modal UI action?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader