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

Hi Harsha , 

Thank you so much for taking the time to write all that , 

We are getting there ,

In Ui Action : (im not using Dailog box)

 

 

find_real_file.png

 

Rest Everything is Perfect . 

Thankyou ,

 

you can mention directly on your client script of UI Page , it will work.

 

If my answer helped you, kindly mark it as correct and helpful.

Hi  Harsha ,

Its not Working .

Here  Ui Action is Inside an Application .

How to pass  currentTableName from Ui action to Client Script/Script-include.

 

Just One more Step , Im  unable to pass Value to client script/ SriptInclude . 

Please guide me to finish this . 

 

is it possible for quick web-ex? of screen-sharing  on google hangout. i can quickly help you.

yes , please .

Just Ping me , i'll reach you . 

My Hangouts Mail  : Tarunr126@gmail.com.