UI page to display table data based on reference type variable

Bhaskar24
Tera Expert

Hi All,

I want to create an UI Page: "Search Asset" to search the assets for the users from the table: "alm_asset" based on Assigned to field.

Fields:

Requested for:

[User lookup table]

My Assets:

Displayed within a read only table within the form

Could you please help me, how to create the UI Page for the above requirement?

Thanks & Regards,

Bhaskar

1 ACCEPTED SOLUTION

Hi Bhaskar,



Another approach using iframe is as follows:



Link will be automatically present since it is a table list layout


Also "Select User" and the "lookup icon" are both in single line since those are included in table tag



Steps/Approach:


1) Select the user


2) iframe will display the table list layout with filter as assigned_to is the user you selected


3) on clicking user can visit the record


4) Also if user is cleared out iframe src attribute is cleared out and div is made hidden


5) If no record found in alm_asset table for that user alert is shown and src attribute cleared and div is made hidden



Drawback:


if user visits the record and clicks on back icon the filter will go.


User can apply his/her own filter and view other records also



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">


      <html>


      <body>


              <table>


              <th>Select User:</th>      


  <th><g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter" onchange="generateTable()"/></th>      


              </table>


              <br/>


              <div id="dvTable" style="display:none">


                      <iframe id="alm_asset" name="alm_asset" src="" style="overflow: hidden; height: 100%;


              width: 100%; position: absolute;" height="100%" width="100%"></iframe>


</div>


      </body>


      </html>


</j:jelly>



Client Script



function generateTable(){


     


      var userSysId = gel('userRecords').value;


     


      if(userSysId!=''){


              var gr = new GlideRecord("alm_asset");


              gr.addQuery("assigned_to", userSysId);


              gr.query();


              if(gr.rows.length > 0){


                      document.getElementById('alm_asset').src = '/alm_asset_list.do?sysparm_query=assigned_toDYNAMIC' + userSysId ;


                      document.getElementById('dvTable').style.display = '';


              }


              else{


                      // no assets foundso clear src of iframe and hide the div


                      alert("No assets found");


                      document.getElementById('alm_asset').src = '' ;


                      document.getElementById('dvTable').style.display = 'none';


              }


      }


      else{


              // remove the src attribute of iframe and show alert and hide the div


              document.getElementById('alm_asset').src = '' ;


              document.getElementById('dvTable').style.display = 'none';


      }


}



I hope this would be enough. Since almost all the coding you have received from my end.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

8 REPLIES 8

Hi Bhaskar,



Another approach using iframe is as follows:



Link will be automatically present since it is a table list layout


Also "Select User" and the "lookup icon" are both in single line since those are included in table tag



Steps/Approach:


1) Select the user


2) iframe will display the table list layout with filter as assigned_to is the user you selected


3) on clicking user can visit the record


4) Also if user is cleared out iframe src attribute is cleared out and div is made hidden


5) If no record found in alm_asset table for that user alert is shown and src attribute cleared and div is made hidden



Drawback:


if user visits the record and clicks on back icon the filter will go.


User can apply his/her own filter and view other records also



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">


      <html>


      <body>


              <table>


              <th>Select User:</th>      


  <th><g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter" onchange="generateTable()"/></th>      


              </table>


              <br/>


              <div id="dvTable" style="display:none">


                      <iframe id="alm_asset" name="alm_asset" src="" style="overflow: hidden; height: 100%;


              width: 100%; position: absolute;" height="100%" width="100%"></iframe>


</div>


      </body>


      </html>


</j:jelly>



Client Script



function generateTable(){


     


      var userSysId = gel('userRecords').value;


     


      if(userSysId!=''){


              var gr = new GlideRecord("alm_asset");


              gr.addQuery("assigned_to", userSysId);


              gr.query();


              if(gr.rows.length > 0){


                      document.getElementById('alm_asset').src = '/alm_asset_list.do?sysparm_query=assigned_toDYNAMIC' + userSysId ;


                      document.getElementById('dvTable').style.display = '';


              }


              else{


                      // no assets foundso clear src of iframe and hide the div


                      alert("No assets found");


                      document.getElementById('alm_asset').src = '' ;


                      document.getElementById('dvTable').style.display = 'none';


              }


      }


      else{


              // remove the src attribute of iframe and show alert and hide the div


              document.getElementById('alm_asset').src = '' ;


              document.getElementById('dvTable').style.display = 'none';


      }


}



I hope this would be enough. Since almost all the coding you have received from my end.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi Bhaskar,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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

Hi Bhaskar,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Bhaskar,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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