How to call UI page from UI action

Sanket Choughul
Tera Contributor

Hi community,

 

I have a requirement to create a barcode. I have create one UI page and UI action but not sure how to pass sys_id of current record to UI page. Can someone help me with the same?

3 REPLIES 3

SwarnadeepNandy
Mega Sage

Hello @Sanket Choughul,

 

To pass the sys_id of the current record to a UI page, you need to use the sysparm_sys_id parameter in the URL of the UI page. This parameter allows you to pass the sys_id of any record to a UI page and access it in the UI page script. For example, if you have a UI page called barcode and you want to pass the sys_id of the current incident record to it, you can use the following URL:

/barcode.do?sysparm_sys_id=${current.sys_id}

You can use this URL in your UI action script to redirect the user to the UI page when they click on the UI action button. You can use the Redirecting users from a UI action - Product Documentation: Rome - ServiceNow article as a reference for redirecting users from a UI action.

On the UI page script, you can use the RP.getParameter() method to get the value of the sysparm_sys_id parameter and use it for your barcode creation logic. You can use the UI Page - Product Documentation: Rome - ServiceNow article as a reference for creating and scripting UI pages.

For more information about how to pass sys_id of current record to UI page in ServiceNow, you can refer to the following links:

I hope this helps you

 

Kind Regards,

Swarnadeep Nandy

Hi Swarnadeep,

I tried by using it by still I am unable to fetch the sys_id of record. For example below is my UI action-

 

function printBarCodeLabel() {
  var sysid  = g_form.getUniqueValue();
  var features = "resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no,width=600,height=400";
  var href = "xyz.do?sysparm_stack=no&sysparm_view=print&sysparm_media=print&sysparm_id=" + sysid;
  win = window.open(href, "Printer_friendly_format", features);
  win.focus();
}
 
Below is my UI page-
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
<j:set var="jvar_x_nuvo_eam_facilities_parts_id" value="${sysparm_x_nuvo_eam_facilities_parts}" />
<g:include_script src="jsbarcode.jsdbx"/>
        
<g:evaluate var="sysparm_id"> 
  var sysparm_id = RP.getParameterValue("sysparm_id");
  sysparm_id; 
</g:evaluate>   
 
<g:evaluate var="jvar_record" object="true" jelly="true"> 
  var gr = new GlideRecordSecure("x_nuvo_eam_facilities_parts"); 
  gr.get(jelly.sysparm_id);
  gr; 
</g:evaluate>

<input type='hidden' name='assetTag' id="assetTag" value="${jvar_record.getDisplayValue('u_upc_number_part')}"  /> 
<!-- <input type='hidden' name='serialNO' id="serialNO" value="${jvar_record.getDisplayValue('serial_number')}" /> -->

<style>  
   td{font-size: 8px;align:center;vertical-align:top;}
   @media print {@page { margin: 0; }}
</style>
    
<table style="width:100% height:100%">
    <tr><td colspan="2"><svg id="barcode"/></td></tr>
    <tr><td>Part Name: ${jvar_record.getDisplayValue('name')}</td>
    <td>Number: ${jvar_record.getDisplayValue('number')}</td></tr>       
    <tr><td colspan="2" align="center"><br/><button type="submit" onclick="javascript&colon; window.top.print();"><img src="images/printer.gifx"></img><span>Click to Print</span></button></td></tr>
</table> 

<script type="text/javascript">
      window.onload = function() { window.print(); }
</script>
    
</j:jelly>
 
client script:-
var barcode = gel("assetTag").value;
var labelText = "Upc number part: " + gel("assetTag").value;
 

Eswar Chappa
Mega Sage
Mega Sage

Hi @Sanket Choughul The below article will help you for the above requirement with code

https://www.servicenow.com/community/itsm-forum/code-to-call-ui-page-from-ui-action-button/m-p/51738...

 

Cheers, hope that helps

Eswar Chappa

*** Please mark as "Correct" or "Helpful" as appropriate ***