HowTo:Add a Custom Print Button to a Form
For: Designers See more: |
This code adds a [Custom Print] button to a Form, when placed in an On Load Form Script.
In this case, the goal is to restrict a user who has access to that form to a specific template. (The standard Print operation makes all templates available. A standard Action button, meanwhile, is present in every form. This code puts the button in a specific form, to restrict template access for users whose role causes it to be displayed.)
- Set up the custom print button
- Go to the Form you want to modify:
- Workspace > {object} > Customize this Object > Forms > {form}
- Click [Form Script]
- Click [Edit]
- In the On Load Script area, enter the code below.
- Click [Save]
- JavaScript code
- <syntaxhighlight lang="javascript" enclose="div">
$("#print_button").remove(); $("#edit_button").parent().append( "<input type='button' id='customPrint' value='Custom Print' class='lj-button fg-button ui-state-default ui-corner-all' onClick=\"javascript:lj_printRecord('default_print_layout=template&show_print_layout=no&default_print_document=jsp&default_page_orientation=landscape&default_pdf=yes&show_pdf=no&print_immediately=yes');\">" ); </syntaxhighlight>
- How it Works
-
- $("#print_button").remove()
- Remove the standard print button
- $("#edit_button").parent().append
- Finds the location of the edit button (present in every form), gets it's parent (the toolbar), and adds the new button to it.
- class='lj-button fg-button ui-state-default ui-corner-all'
- The standard CSS style elements for platform buttons.
- <input type='button' ...
- Define the button. (The entire string is one uninterrupted line.)
- onClick=\"javascript:lj_printRecord(...
- Specify the button's action
Learn more: JavaScript Functions#lj_printRecord