- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 11:55 PM
Hi ,
I have a Requirement : when Ui Button is Clicked , it will Render a Ui Page with Dynamic Values .
Ui Page : will Fetch values of Specified Table from Script Include using GlideAjax.
Script Include : Has Code to glide Records from Specified Table and will Pass it to Ui page .
working fine .
(But I want Script Include to Glide Records from Different Tables . Before, i specified from which Table records needs to be Glide in Script Include .) now
Different Button-Clicks should Display Different Records in Ui Page .
More Info : I have 10 Tables , Each Table has a custom Ui Button .(ui actions)
Table 1 has ,Button 1
Table 2 has Button2
When Button 1 : OnClick() -Pass SysId of Table1 to Script Include ( i thought of Bussiness Rule )
Script include has Code to glide records in that Table .
Question :
Flow :
1.Ui Button will call Uipage
2. Ui page Will Call Script-Include(GlideAjax)--------------[ Here I want Dynamic Data ,When Different Buttons are clicked ]
3.What ever data Returned from Script-Include will be Displayed in Ui page .
How to Pass Dynamic Values to Script Include Without Disturbing this Flow ???
Kindly Help me ,
Any Suggestion is Appreciated .
Thankyou ,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 02:18 AM
are you using GlideDialogWindow in ui action ? if yes then you can send the table name from ui action to ui page ,
eg:
function commentsDialog() {
//Get the values to pass into the dialog
var tabName = g_form.getTableName();
//Initialize and open the Dialog Window
var dialog = new GlideDialogWindow("<ui page name>");
dialog.setTitle("Add Task Comments"); //Set the dialog title
dialog.setPreference("table_text", tabName );
dialog.render(); //Open the dialog
}
UI page:
HTML:
<g:ui_form>
<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_text"
expression="RP.getWindowProperties().get('table_text')" />
one html field to store the table name , you can also make it as hidden html field
<g:ui_multiline_input_field name="tab_name" id="tab_name" label="table name" value="${jvar_text}" />
<g:dialog_buttons_ok_cancel ok="return validateComments()"ok_type="button" cancel_type="button" />
</g:ui_form>
Access the variable value in client script of your UI Page:
function validateComments() {
//Gets called if the 'OK' dialog button is clicked
//Make sure dialog comments are not empty
var tabName = gel("tab_name").value;
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', tabName);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
GlideDialogWindow.get().destroy(); //Close the dialog window
}
Script Include:
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var tbName = this.getParameter('sysparm_user_name');
var gr = new GlideRecord(tbName);
gr.query();
while(gr.next()){
// further script
}
return "Hello " + "!";
} ,
_privateFunction: function() { // this function is not client callable
}
});
Hope it will help you now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 12:00 AM
Hello Tarun,
May I ask you to explain us what is the initial requirement?
It will be easier for us to understand what you would like to achieve, and maybe you are going to the wrong direction.
Because, initially I would like to say, you can easily pass values to script include directly like this:
var answer = new $scriptInclude$().$function$($param1, $param2);
However I do not understand the "without disturbing this flow" aspect.
Thank you,
Ben
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 12:07 AM
Hi Tarun,
You can achieve it in this way:
For example
// Instantiate the GetEmailAddress Script Include
var getEmailAddr = new GlideAjax('GetEmailAddress');
// Specify the getEmail method
getEmailAddr.addParam('sysparm_name','getEmail');
// Pass the Requested for sys_id
getEmailAddr.addParam('sysparm_tableID', ('sys_id of table you are on to'));
// Send the request to the server
getEmailAddr.getXML(populateEmailField);
script include:
var GetEmailAddress = Class.create();
// Extend the global.AbstractAjaxProcessor class
GetEmailAddress.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
getEmail: function() {
var userRecord = new GlideRecord("sysparm_tableID");
//your code in gliding table
},
type: 'GetEmailAddress'
});
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 12:10 AM
as you have mentioned " I have 10 Tables , Each Table has a custom Ui Button .(ui actions)" , so you can pass one param to fetch the table name "g_form.getTableName() " and then use in your script include
eg:
var ga = new GlideAjax('HelloWorld'); ga.addParam('sysparm_name', 'helloWorld'); ga.addParam('sysparm_user_name', g_form.getTableName()); // here i have passed the table name it will work dynamically ga.getXML(HelloWorldParse); function HelloWorldParse(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert(answer); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 12:18 AM
Yes I do agree with this answer.
Or if you want to do it directly on a server script: current.getTableName()
In your case, you have to send the table name to the UI page from the UI action.
Then you can pass the table name to the script include like that:
var answer = new $scriptInclude$().$function$($param1, $param2);