Changes

Passing Values Using Parameters

458 bytes added, 17:39, 20 October 2017
no edit summary
Using several techniques , you can pass values a value (called a Parameter) from one page to another in order to pre-populate form fields or display on an HTML page. This is done by creating links with parameters.
==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. '''PortalSyntax:''':<font size="3">'''/urltopage?var1=@variable1@&var2=@variable2@'''</font>  '''Where:'''* Create a ''urltopage'' is the relative [[PortalURL]] shortcut and associate to the destination page.* ''variable1'', ''variable2'' etc. are the link with that shortcutvariable names (e.g. @firstname@).* ''var1'', ''var1'' corresponding names for the variables
<pre>
/urltopage?parameter1=@variable1@&parameter2=@variable2@
</pre>
User and Company variables can be used to pass the current logged in user details and their company details.<u>'''Examples:'''</u>
'''ApplicationPortal'''* Create a [[Custom FieldPortal]] of shortcut and associate the type [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] link with one of the followingthat shortcut. /urltopage?var1=@variable1@&var2=@variable2@
'''Display as buttonButton'''* 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?parameter1var1=@variable1@&parameter2var2=@variable2@"'/>
</pre>
 '''Display as hyperlinkHyperlink'''* Create a [[Custom Field Type: Read Only – System Variables|Read Only - System Variables]] Custom Field with:
<pre>
<a href="/urltopage?parameter1var1=@variable1@&parameter2var2=@variable2@">Click Here</a>
</pre>
Replace "variable1" with '''Note''': User and Company variables can be used to pass the actual variable name current logged in user details and "parameter1" with a corresponding name (eg. firstname=@firtsname@)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.
==Parsing Parameters== 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 htmlHTML.
<pre>
Place one of the following second functions in within the bodyjust prior to the closing body tag (&lt;/body>).
var para2=document.getElementById('field2');
para1.value = unescape(params["parameter1var1"]);para2.value = unescape(params["parameter2var2"]);
var para2=document.getElementById('element2');
para1.value = unescape(params["parameter1var1"]);para2.value = unescape(params["parameter2var2"]);
</script>
Replace "field1" or "element1" etc. with the actual form or element id name and "parameter1var1" with the parameter name.
eg.
[[SmartSimple]] will replace the variable references (@lastname@ , etc.) with values derived from the current [[User|user]] session. 
[[Category:JavaScript]]
==See Also==* [[Category:System Management]][[Category:JavaScriptPass Variables To Level 1]]
Smartstaff, administrator
686
edits