The Zurich release has arrived! Interested in new features and functionalities? Click here for more

get value from g:ui_reference?

arey yaar
Giga Guru
 

i need to get the value from  "g:ui_reference"  for the sys_script(which displays all the tables).when i select the table and click on download it should download all the records in Xlsx format.Suppose if we have an incident table selected ..the incident table which consists of active records must be downloaded in Xlsx format.

1 ACCEPTED SOLUTION

Hi Subhanand,

Following script you can use in 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:evaluate var="jvar_instanceName" object="true">
var instanceName = gs.getProperty('instance_name');
instanceName;
</g:evaluate>

<g:ui_reference name="tables" id="tables" table="sys_db_object" completer="AJAXTableCompleter"/>
<input type="hidden" id="hidden" value="${jvar_instanceName}"/>
<input type="button" value="Download Excel" onclick="download()"></input>

</j:jelly>

Client Script:

function download(){

var instanceName = gel('hidden').value;

var table = gel('tables').value;

var tableGr = new GlideRecord('sys_db_object');
tableGr.addQuery('sys_id', table);
tableGr.query();
if(tableGr.next()){
var url = 'https://' + instanceName + '.service-now.com/' + tableGr.name + '_list.do?XLS';
window.open(url);
}
}

Care to be taken since it doesn't specify any query so it will try downloading all records. you can specify the view as well so as to include only necessary columns using sysparm_view parameter in URL

Mark Correct if this solves your issue and also mark 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

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Subhanand,

 

To which table the ui_reference is pointing to? Is it showing list of all tables?

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

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

yes it shows the list of all tables, the selected tables must download all the records (suppose we have selected incident table then the incident records should be downloaded in Xlsx format).

Hi Subhanand,

Following script you can use in 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:evaluate var="jvar_instanceName" object="true">
var instanceName = gs.getProperty('instance_name');
instanceName;
</g:evaluate>

<g:ui_reference name="tables" id="tables" table="sys_db_object" completer="AJAXTableCompleter"/>
<input type="hidden" id="hidden" value="${jvar_instanceName}"/>
<input type="button" value="Download Excel" onclick="download()"></input>

</j:jelly>

Client Script:

function download(){

var instanceName = gel('hidden').value;

var table = gel('tables').value;

var tableGr = new GlideRecord('sys_db_object');
tableGr.addQuery('sys_id', table);
tableGr.query();
if(tableGr.next()){
var url = 'https://' + instanceName + '.service-now.com/' + tableGr.name + '_list.do?XLS';
window.open(url);
}
}

Care to be taken since it doesn't specify any query so it will try downloading all records. you can specify the view as well so as to include only necessary columns using sysparm_view parameter in URL

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

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

what if i need an encoded query too..by selecting the table and giving condition in the other field instead of giving it on the url manually