Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to pass current record sys id from ui action to ui page in workspace?

Ankita Kolhe
Tera Contributor

Hi Community,

Having an UI Action in workspace & on click of that UI Action ,an UI Page should gets open. There I need to validate the sys id of the current record but I'm struggling with it.

 

UI Action:-

I'm passing sys id of record in url & trying to retrieve in UI Page html.

 

AnkitaKolhe_1-1704368509507.png

 

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">
<label for="${jvar_app_query}" onclick="" dir="">${gs.getMessage("Parent Entity")}</label>
 
<input type="text" name="myparam" value="${sysparm_sysid}"/>
 
<g:ui_reference style="width:20px" query="active=true" name ="entity_name" id="entity_name" table="x_kpm79_kpmgi_iogc_kpmgi_iogc_entity_management_base" />
<button type="button" class="button button1" style="background-color: #04AA6D" onclick="test()">Ok</button>
</j:jelly>

 But the sys id value is not getting populated in text box;-
 
AnkitaKolhe_2-1704368797900.png

 

Can someone please help in this?

 

 
 
 

 

4 REPLIES 4

umaaggarwal
Giga Guru

check the URL you are forming correct? Can you check this url manually providing sys id in browser? Does it work?

Also, I would suggest define a variable url outside show frame. Something like below

 

var url = 'define your url here' ( test it manually and make sure it is correct)

g_modal.showFrame({

title : 'yout title here',

url :url,

size: 'fw'

});

 

Ankur Bawiskar
Tera Patron

@Ankita Kolhe 

${sysparm_sysid} will work only when UI page is called using GlideDialogWindow when you set the preference

In your case you can get the URL value and parse and get the sysId

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

Hi @Ankur Bawiskar ,

 

Thanks for the response. Could you please help with the code to parse sys id?

 

Hi @Ankita Kolhe 
We can pass the sys_id of current record in the URL of UI Page from UI Action Workspace Client Script:
var url = '/' + uiPage + '.do?sysparm_meeting_id=' + meetingId + '&sysparm_workspace=true';

g_modal.showFrame({
url: url,
title: 'Add Visitors',
size: 'xl'
});

In UI Page client script, a function to fetch the sys_id from URL is configured.

function getParameterByName(name) {

    var url = window.location.href;

    name = name.replace(/[\[\]]/g, "\\$&");

    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");

    var results = regex.exec(url);

    if (!results) return null;

    if (!results[2]) return '';

    return decodeURIComponent(results[2].replace(/\+/g, " "));

}

function submitVisitors() {

    var meetingId = getParameterByName('sysparm_meeting_id');

}