Page Script Walkthrough
- Understand the example
- Add the script to a page
- Debug inline page scripts
- Use record-in-scope data
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.
- Save your changes.
Give yourself permissions for the new menu (Company > Users View Permissions & Roles …).
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
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.