Page Script Walkthrough
- Set up Platform Services preferences
- Understand the example
- Add the script to a page
- Debug inline page scripts
- Use record-in-scope data
You can add your own client-side scripts to pages in the Sage Intacct UI.
Set up Platform Services preferences
If you haven’t already done so, configure your preferences (in the UI) so that you can use syntax highlighting, auto completion, and script component debugging when working on scripts in Platform Services.
Set the Layout type to Action UI and make sure Script component debug all scripts is On:
Platform Services uses the CodeMirror® library to provide syntax highlighting, for example:
Understand the example
Let’s first look at the example (below) and note some key points. At the top, you see that two text entry fields (CUSTOMER ID and CUSTOMER Name) are provided inside a
div tag whose ID is
newCustomer. A Create Customer button that calls a
div tag, an inline style is provided for it according to its ID. This is a best practice as it helps avoid unwanted restyling of page elements. (This is especially true on standard object pages where standard elements may not have
id attributes rigorously assigned.)
createCustomer function implemented in the script. After logging a status message, the function populates an array with name/value pairs. The name is the parameter name for the
create XML API call, and the corresponding value is accessed from the text entry field using jQuery (
API_session constructor is used to instantiate the SDK class and start a session (using the credentials of the current user).
A callback is then defined to capture the server response via the AJAX
responseText property, then print that response to the console.
ip_create call provides the name of the object, the array of field values, and the callback as parameters.
Note the use of
Add the script to a page
Now lets add the script to a custom menu/page in a Platform Services app.
If you don’t have a Platform Services app, you can add the script to an existing page, such as a standard object page. Note that this approach creates a one-off script, which will not be available when a Platform Services app is exported/installed.
- From Platform Services, add a new menu:
- Name the menu myTestMenu.
- Choose the Generic Menu Type.
- Add the menu to your application.
- Save your changes.
See the Sage Intacct product help for more information about creating menus and pages.
Add the script to the associated page:
- List the menus from Platform Services and click your menu name.
Click Edit Page to open the Page Editor.
- Drag a New <Script Component> onto the default fields section of the editor.
- Edit the script component and paste in the code below.
- Add a name and a description in the Script Component Info section below the code.
- Scroll to the bottom and save your changes, then save again at the top of the page editor.
Give yourself permissions for the new menu using Company > Users > Subscriptions.
Test your script by creating a test customer.
The callback in the script prints the response from the server to console. For example, here’s a sample response shown in Chrome:
Note: You can ignore messages about Content-length and Connection headers.
Don’t forget to delete the test customer when finished.
Debug inline page scripts
Assuming you configured your preferences (above), any page script will automatically have a file name that you can use for debugging purposes.
The debug file name follows the naming conventions pt_script_<originalId>_<scriptIndex>.js. If there are multiple scripts on a page, the index number increments.
As an alternative, you can disable the preference for script component debugging on all scripts, then manually insert a debug file name using a comment in your script code, for example:
This name is only available when the preference for script component debugging is turned off.
Use record-in-scope data
On Platform Services pages, you can use merge fields in your scripts to access data from the record in scope. The script editor within the page element has a built-in merge field tool to look up merge fields for the object you are working with. Merge fields here follow the same format they would in any other Platform Services script.