Difference between revisions of "JavaScript Functions"

From AgileApps Support Wiki
imported>Aeric
m (Text replace - 'Print Template' to 'Document Template')
imported>Aeric
(Replaced content with "A variety of JavaScript functions are available, depending on the context in which JavaScript is running. :* For Form Scripts and Field Scripts, see [[Referencing...")
Line 1: Line 1:
These functions are available anywhere that [[JavaScript]] is running on the platform.
A variety of [[JavaScript]] functions are available, depending on the context in which JavaScript is running.
__TOC__
:* For [[Form Scripts]] and [[Field Scripts]], see [[Referencing Form Fields in JavaScript]]
Β 
:* For ___, see [[ | ]]
{{Note|Examples on this page have newlines added for readability.}}
Β 
====showTab====
Display an object ''list view'' (list of object records) as a tab in the GUI.
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
showTab(key, tabTitle, url);
</syntaxhighlight>
Β 
;Parameters:
:* '''key -''' Unique key that identifies the tab. Object ID is recommended.
:* '''tabTitle -''' The tab label.
:* '''url -''' The URL used to render the view, in the form: <tt>Service?t=499&object_id={id}</tt>
:: Optionally, add <tt>&show_layout={viewId}</tt> to specify a particular view.
Β 
''Learn more:''
:* [[Get an Object ID]]
:* [[Get a View ID]]
Β 
;Sample Usage:
Here is the basic usage pattern:
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTab('{objectId}','{Tab title}',
'Service?t=499&object_id={objectId}');">{Link title}</a>
</syntaxhighlight>
Β 
Show the default view of the Orders Object (ID=<tt>bd5b766236dd487c8cce3648bd5ffe64</tt>)
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTab('bd5b766236dd487c8cce3648bd5ffe64','Orders',
'Service?t=499&object_id=bd5b766236dd487c8cce3648bd5ffe64');">View Orders</a>
</syntaxhighlight>
Β 
Show a specific view with ID <tt>de5dnnn8798</tt>, instead of the default view:
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTab('bd5b766236dd487c8cce3648bd5ffe64','Orders',
'Service?t=499&object_id=bd5b766236dd487c8cce3648bd5ffe6464
&show_layout=de5dnnn8798');">Orders</a>
</syntaxhighlight>
Β 
====showTabInIFrame====
Display a record form as a tab in the GUI, using the form either to add a record to an object or to display record details.
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
showTabInIframe(key, tabTitle, url, preserveTabTitle);
</syntaxhighlight>
Β 
;Parameters:
:* '''key -''' Unique key that identifies the tab. <tt>{objectId}-1</tt> is recommended.
::* When a new record is displayed using that key, the tab is reused. Adding a dash and a one differentiates the record tab from a view tab.
::* Using the record ID for that purpose isn't recommended, because records in different objects could conceivably have the same record ID.
::* To make every record open in a different tab, you could use <tt>{objectId}-{recordId}</tt>
Β 
:* '''tabTitle -''' The tab label.
::* When displaying a record, the label is overwritten with the Object name and the [[Record Identifier]]
::* Standard practice in that case is to use it as a temporary label. For example: <tt>'Loading...'</tt>
Β 
:* '''url -''' The URL used to display the record: <tt>Service?t=498&object_id={id}</tt>
::* Add <tt>&id=-1&a=add</tt> to add a new record
::* Add <tt>&id={recordId}&a=view&policyaction=view</tt> to display an existing record
::: (In each case, the [[Form]] used to display the record (or gather data for it) is determined by the user's [[Role]] and the action being performed.)
:* '''displayTitle -''' Boolean value that determines whether or not the specified title is used.
::* If true, the specified title is used for the tab label. (Must be true for a temporary label to be displayed, as well.)
::* If false, the Object name is used, instead.
Β 
''Learn more:''
:* [[Get an Object ID]]
:* [[Get a Record ID]]
Β 
;Sample Usage:
Here is the basic usage pattern:
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTabInIframe('{objectId}-1','{Tab title}',
'Service?t=498&id=-1&a={action}&object_id={objectId}', true);">{Link Title}</a>
</syntaxhighlight>
Β 
This example opens a tab to add a record to the Orders Object (ID=<tt>bd5b766236dd487c8cce3648bd5ffe64</tt>):
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1',
'New Order','Service?t=498&id=-1&a=add&object_id=bd5b766236dd487c8cce3648bd5ffe64');">
Add Order</a>
</syntaxhighlight>
Β 
This example opens a tab to display a record, where:
:* objectID = 088d7ac50c4349b5b08d06cc8fa4e732
:* recordID = 255796565
:<syntaxhighlight lang="javascript" enclose="div">Β  Β 
<a href="javascript:top.showTabInIframe('088d7ac50c4349b5b08d06cc8fa4e732-1', Β 
'Loading...','Service?t=498&id=255796565&object_id=088d7ac50c4349b5b08d06cc8fa4e732
&a=view&policyaction=view', true);">Details</a>
</syntaxhighlight>
Β 
:''Learn more:'' [[HowTo:Use a SQL Query to List Records in a Custom Page]]
Β 
====lj_closeDialog====
Close the current dialog. Typically used in conjunction with [[#lj_refreshCurrentTab|<tt>lj_refreshCurrentTab</tt>]].
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_refreshCurrentTab();
</syntaxhighlight>
Β 
;Sample Usage:
{{:JavaScript closeDialog Sample}}
Β 
====lj_printRecord====
This function displays a customized print dialog for a record. Use it to set defaults, to limit the available choices, and to choose the [[Document Template]] which is used. (It is only available for {{type|}}s.)
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_printRecord('{option1}={value}&{option2}={value}&...');
</syntaxhighlight>
Β 
;Parameters:
Each option has two parameters: One to specify a default value, the other to determine whether it should be displayed so it can be overridden by the user.
Β 
By default, an option is always shown, unless explicitly hidden.
Β 
:{| border="1" cellpadding="5" cellspacing="1"
! align="left"| Parameter !! align="left"| Description
|-
| default_print_layout || '''form''' (default) - use a [[Print Form]]<br>'''template''' - use a [[Document Template]]
|-
| show_print_layout || '''yes''' (default) - allows user to specify which kind of layout to use
|-
| default_print_document || The name of the form or template to pre-select in the list of possible choices.
|-
| show_print_document || '''yes''' - allows user to change the default choice
|-
| print_immediately || '''no''' (default) - The print dialog is shown. The user can then change any options that are displayed. Printing occurs when the user clicks the Print button).<br>'''yes''' - printing occurs immediately and the results are displayed in a new window. (It only works if both <tt>default_print_layout</tt> and <tt>default_print_document</tt> are specified.)
|-
| default_page_orientation || '''portrait''' (default) or '''landscape'''
|-
| show_page_orientation || '''yes''' - allows user to change page orientation
|-
| default_pdf || '''yes''' - otherwise, an HTML page is generated
|-
| show_pdf || '''yes''' - allows user to choose HTML or PDF
|}
Β 
;Sample Usage:
{{:HowTo:Add a Custom Print Button to a Form}}
Β 
====lj_refreshCurrentTab====
Refresh the current tab. Typically used in conjunction with [[#lj_closeDialog|<tt>lj_closeDialog</tt>]]
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_refreshCurrentTab();
</syntaxhighlight>
Β 
;Sample Usage:
{{:JavaScript closeDialog Sample}}
Β 
====lj_refreshTab====
Refresh a specific tab. Typically used in conjunction with [[#lj_closeDialog|<tt>lj_closeDialog</tt>]]
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
{window}.lj_refreshTab();
</syntaxhighlight>
Β 
;Sample Usage:
{{:JavaScript closeDialog Sample}}
Β 
====lj_showDialog====
This function displays a JSP/HTML [[Page]] as a dialog.
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_showDialog(url, height, width, "dialog style", "title");
</syntaxhighlight>
Β 
;Parameters:
Β 
:{| border="1" cellpadding="5" cellspacing="1"
! align="left"| Parameter !! align="left"| Description
|-
| url || A string that gives the URL of a JSP/HTML [[Page]] in the platform, in the form <tt>/networking/pages/SomePage.jsp</tt> with optional query parameters to pass data: <tt>?param1=abc&param2=xyz&...</tt>
|-
| height ||Β  The height of the dialog window, in pixels.
|-
| width || The width of the dialog window, in pixels.
|-
| dialog style || A string that specifies the display style.
:* '''popupdialogWithCloser -''' Displays the dialog with a close button.
:* '''popupdialog -''' Displays the dialog without a close button.
:: ''Note'':<br>There is also no close icon in the corner, with this option.<br>When using it, add your own controls to close the dialog.
|-
| title || Displayed in the banner of the dialog.
|}
;Sample Usage:
This sample displays a page at the specified URL in a popup dialog that has a close button.
Β 
:<syntaxhighlight lang="javascript" enclose="div">
var url = "/networking/pages/MyPage.jsp?recordId="+someValue
Β  Β  Β  Β  + "&returnUrl="+encodeURIComponent(lj_window_src);
Β 
top.lj_showDialog(url,300,350,"popupdialogWithCloser","My Page Title");
</syntaxhighlight>
<noinclude>
<noinclude>


[[Category:JavaScript APIs]]
[[Category:JavaScript APIs]]
</noinclude>
</noinclude>

Revision as of 01:03, 29 June 2013

A variety of JavaScript functions are available, depending on the context in which JavaScript is running.