Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Passing Values to script Include??

Tarun2
Tera Contributor

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 ,

 

 

1 ACCEPTED SOLUTION

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. 

View solution in original post

24 REPLIES 24

Tarun2
Tera Contributor

Hi ,

Yes! This is what i meant .

Can you please  Explain me How to Execute this Code in Detail ?

 

Thanks

Tarun2
Tera Contributor

Hi thanks for your Response ,

I want to Display Records of a Particular  Table in a Ui page . 

 

 What i'M doing :

1.Ui Button onClick() : 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 . 

 

                                  Ui page below

Account : Table name 

Contact : Records

 

                       Code in Glide Ajax

I want to Glide Records of Multiple Tables as per requirement .( Dynamic Table name )

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 .

likewise Button2 On click() should display , Table2 Records in ui Page .

 

Thankyou ,

 

where is your glide ajax code? the code which you have added thats script include code

Hi ,

Code in Client Sript of ui page :

var value = [];
var answer;
var ga = new GlideAjax('Getting');
ga.addParam('sysparm_name','Function_Name');
ga.getXML(ProcessResult);
function ProcessResult(response) {
answer = response.responseXML.documentElement.getAttribute("answer");

 

quick question, are you using your ui page in your UI Action ? 

 

try now. 

 

var value = [];
var answer;
var ga = new GlideAjax('Getting');
ga.addParam('sysparm_name','Function_Name');

ga.addParam('sysparm_tab_name', g_form.getTableName());
ga.getXML(ProcessResult);
function ProcessResult(response) {
answer = response.responseXML.documentElement.getAttribute("answer");

 

Now use "sysparm_tab_name" variable on your script include