Difference between revisions of "Passing Values Using Parameters"

From SmartWiki
Jump to: navigation, search
(Passing Parameters to the Link)
 
(41 intermediate revisions by 4 users not shown)
Line 1: Line 1:
You can create links using several techniques:
+
Using several techniques, you can pass a value (called a Parameter) from one page to another in order to pre-populate form fields or display on an HTML page.
  
In the context of a [[Portal|portal]] interface by using a link:
+
==Sending Page==
 +
Values can be sent from the initial (sending) page by creating a link to the destination page that includes parameters linking the variables to be passed. These are then parsed by the receiving page back into values.
 +
 
 +
'''Syntax:'''
 +
:<font size="3">'''/urltopage?var1=@variable1@&var2=@variable2@'''</font>
 +
 
 +
 
 +
'''Where:'''
 +
* ''urltopage'' is the relative [[URL]] to the destination page.
 +
* ''variable1'', ''variable2'' etc. are the variable names (e.g. @firstname@).
 +
* ''var1'', ''var1'' corresponding names for the variables
 +
 
 +
 
 +
<u>'''Examples:'''</u>
 +
 
 +
'''Portal'''
 
* Create a [[Portal]] shortcut and associate the link with that shortcut.
 
* Create a [[Portal]] shortcut and associate the link with that shortcut.
   
+
  /urltopage?var1=@variable1@&var2=@variable2@
In the context of a specific [[Application|application]] by using a [[Custom Field|custom field]]:
+
 
* Create a [[Custom Field]] of the type [[Custom Field Type: Display Only – Text or System Object|Display Only – Text or System Object]]. Add the link to that field.
+
 
* Create a [[Custom Field]] of the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] with the following. It will display as a button.
+
'''Button'''
 +
* Create a [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] Custom Field with:
 +
<pre>
 +
<input type="button" class=Button value="Button Label"
 +
onClick='parent.location.href="/urltopage?var1=@variable1@&var2=@variable2@"'/>
 +
</pre>
 +
 
 +
 
 +
'''Hyperlink'''
 +
* Create a [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] Custom Field with:
 +
<pre>
 +
<a href="/urltopage?var1=@variable1@&var2=@variable2@">Click Here</a>
 +
</pre>
 +
 
 +
'''Note''': User and Company variables can be used to pass the current logged in user details and their company details.
 +
 
 +
==Receiving Page==
 +
 
 +
On the receiving page the parameters can pre-populate a form or an HTML element which resides on that page. In order to achieve this the following [[JavaScript]] functions can be used.  
 +
 
 +
Place the following first function in the head of the HTML.
 +
 
 +
<pre>
 +
function getParams() {
 +
var idx = document.URL.indexOf('?');
 +
var params = new Array();
 +
if (idx != -1) {
 +
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
 +
for (var i=0; i<pairs.length; i++) {
 +
nameVal = pairs[i].split('=');
 +
params[nameVal[0]] = nameVal[1];
 +
  }
 +
}
 +
return params;
 +
}
 +
params = getParams();
 +
</pre>
 +
 
 +
 
 +
Place one of the following second functions within the body just prior to the closing body tag (&lt;/body>).
 +
 
 +
 
 +
'''Form Field Population'''
 +
 
 
<pre>
 
<pre>
<input type="button" class=Button value="Button Label" onClick='parent.location.href="/urltopage?variable=@variable@"'/>
+
 
 +
<script>
 +
 
 +
var para1=document.getElementById('field1');
 +
var para2=document.getElementById('field2');
 +
 
 +
para1.value = unescape(params["var1"]);
 +
para2.value = unescape(params["var2"]);
 +
 
 +
 
 +
</script>  
 +
 
 
</pre>
 
</pre>
  
  
 +
'''HTML Element Population (eg. &lt;div>, &lt;span>)'''
 +
 +
<pre>
 +
 +
<script>
  
 +
var para1=document.getElementById('element1');
 +
var para2=document.getElementById('element2');
 +
 +
para1.value = unescape(params["var1"]);
 +
para2.value = unescape(params["var2"]);
 +
 +
</script>
 +
 +
</pre>
 +
 +
 +
Replace "field1" or "element1" etc. with the actual form or element id name and "var1" with the parameter name.
 +
 +
eg.
 +
 +
var para1=document.getElementById('firstname');
 +
 +
&lt;input type="text" value="" id="firstname">
 +
 +
or
 +
 +
var para1=document.getElementById('firstname');
 +
 +
&lt;div id="firstname">&lt;/div>
  
  
  
In either case the link can be web [[URL]] or local '''UNC''' type link.
 
 
   
 
   
==Passing Parameters Through a Link==
 
 
You can pass values using parameters to another page which has form fields to be pre-populated.  For [[URL]] type links the following syntax would be used:
 
 
  
'''urltopage?Firstname=@firstname@&lastname=@lastname@&email=@email@&address=@address@&address2=@address2@&phone=@phone@&extension=@uphoneext@'''
 
'''&city=@city@&province=@province@&postal=@postalcode@&homephone=@home phone@&companyname=@company name@&employeeid=@employee id@'''
 
  
 +
[[SmartSimple]] will replace the variable references (@lastname@, etc.) with values derived from the current [[User|user]] session.
  
[[SmartSimple]] will replace the variable references (@lastname@ etc) with values derived from the current [[User|user]] session.
 
  
 +
[[Category:JavaScript]]
  
[[Category:System Management]][[Category:JavaScript]]
+
==See Also==
 +
* [[Pass Variables To Level 1]]

Latest revision as of 12:39, 20 October 2017

Using several techniques, you can pass a value (called a Parameter) from one page to another in order to pre-populate form fields or display on an HTML page.

Sending Page

Values can be sent from the initial (sending) page by creating a link to the destination page that includes parameters linking the variables to be passed. These are then parsed by the receiving page back into values.

Syntax:

/urltopage?var1=@variable1@&var2=@variable2@


Where:

  • urltopage is the relative URL to the destination page.
  • variable1, variable2 etc. are the variable names (e.g. @firstname@).
  • var1, var1 corresponding names for the variables


Examples:

Portal

  • Create a Portal shortcut and associate the link with that shortcut.
/urltopage?var1=@variable1@&var2=@variable2@


Button

 <input type="button" class=Button value="Button Label" 
 onClick='parent.location.href="/urltopage?var1=@variable1@&var2=@variable2@"'/>


Hyperlink

<a href="/urltopage?var1=@variable1@&var2=@variable2@">Click Here</a>

Note: User and Company variables can be used to pass the current logged in user details and their company details.

Receiving Page

On the receiving page the parameters can pre-populate a form or an HTML element which resides on that page. In order to achieve this the following JavaScript functions can be used.

Place the following first function in the head of the HTML.

function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();


Place one of the following second functions within the body just prior to the closing body tag (</body>).


Form Field Population


<script>

var para1=document.getElementById('field1');
var para2=document.getElementById('field2');

para1.value = unescape(params["var1"]);
para2.value = unescape(params["var2"]);


</script> 


HTML Element Population (eg. <div>, <span>)


<script>

var para1=document.getElementById('element1');
var para2=document.getElementById('element2');

para1.value = unescape(params["var1"]);
para2.value = unescape(params["var2"]);

</script> 


Replace "field1" or "element1" etc. with the actual form or element id name and "var1" with the parameter name.

eg.

var para1=document.getElementById('firstname');

<input type="text" value="" id="firstname">

or

var para1=document.getElementById('firstname');

<div id="firstname"></div>




SmartSimple will replace the variable references (@lastname@, etc.) with values derived from the current user session.

See Also