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

Sample code i am adding, to call client callable script include using glide ajax. 

 

Client callable 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     
    }
 });

 

Client side script:

 

var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', g_form.getTableName());
ga.getXML(HelloWorldParse);
 
function HelloWorldParse(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  alert(answer); }

 

Now if you see , i have passed table name in client side of script, dynamically it will fetch the table name and you can use that in your script include for further glide record. 

Hi Thanks for your rsponse but ,

Actually my requirement is :

   I have an App , In that  i Have Multiple Table , Each Table has a Ui action Buton .

*When Button is clicked , i want to pass Current Table name to Script-Include .

find_real_file.png

 and Ui page will display these records. 

 

How to PASS Values from Ui actions to Script Include ???

Thankyou ,

did you try with the script which i had shared? it did not work ? 

Hi harsha and @Ben  Thanks but , You Didnt Understood my Requirement 

SHOULD Send Table name 

Ui action -> Ui page -> Scipt Include -> Display on Ui Page .

Did you get it .

Does the Above code work , Can you Explain How to , where to write The Above code

new $script Include$().$function$($param1, $param2).

 

Thanks 

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.