We've already seen how you can create forms using User-Defined Pages, but that framework is limited because it's almost primarily done through the UI. If you want to create model form screens relatively fast but also add in some custom logic, you may want to try the Model Form framework.
When opening a model detail screen via a model link or hyperlink from a report, the User-Defined Pages framework will take precedence over the Model Form framework and custom screens. In other words, if I click a link to a
ZBKS.Book detail screen and there's a User-Defined Page for
ZBKS.Book that matches my User Context, it will open that screen rather than any screen that's been registered for
One.PageMgr.regDetail() function is discussed below.)
Model Forms are implemented through a combination of two artifacts:
- You configure Actions and Views in the MPT to govern what fields are sent from the server to the UI, what fields are editable, etc.
Create a new file called "BookDetail.js" in the
Place the following code in this file:This script effectively states that:
- This will be used for the custom model "Standard ZBKS.Book". (We will discuss custom models more later, but for now you should be aware that there is a "Standard" custom model for every model you design in your module. Thus for ZBKS.Book, we have "Standard ZBKS.Book".)
- There should be an action in the MPT called
"ZBKS.Create" which we will use when creating Books. (In fact, we already created that action in the MPT earlier in the tutorial.)
- There should be a View in the MPT called ZBKS.BookFormDetail which will be used to display the Book in read-only mode. (We will create this momentarily.)
- Detail pages (pages in read-only mode) should display an Audit Trail button, which we'll elaborate on later.
Now that we've created the js module containing our detail page, we need to register it.
To achieve this, we should add the following line to
web/public/GlobalRegistry.js. This contents of this file (and any others you add in
build.jsb) are included into a single
instance.jsthat is loaded on every page in the application.
Next let's open the MPT, navigate to Book in the Outline view, go to the
Actionstab and select the
ZBKS.Createaction you added earlier. Navigate to the
Action Screen > Detail Viewwithin this action. Here you should add some fields to the Book for editing purposes. (Choose any fields you like.)
Next, navigate to the
Viewsand add a view called
Detail. Add some retrieval fields, and give permission to ZBKS.SampleRoleType. (This might not work if you already created a "User-Defined Page" for Book, as that takes precedence over the model form. To continue with this exercise, either delete the user-defined page for Book or setup different criteria in its Page Rule so it won't be matched.)
When you're done, submit the MPT.
Now that the model form is registered, if you search for Books using the Books by Title view, you will see that the book title is now available as a hyperlink. Pressing that link should show a detail page that corresponds to the fields you chose in you ZBKS.BookFormDetail View.
You'll notice on the left side of the toolbar for this page, there is an icon:
This button opens the audit trail for the instance, which allows you to see changes to fields on the model when actions are executed. Before we do that, we need to create an audit trail view. Open the MPT and navigate to Book in the Outline view.
Audit Enabledcheck box for the model:
Then save the MPT and submit it.
Navigate to the
Viewstab and add a view of type
Audit Trail View. The name is not important, so you can just call it
Select a few fields to retrieve for the view, and on the
Permissionstab, give access to
ZBKS.SampleRoleType. Then save the MPT and submit it.
After submitting the MPT, the icon should open the audit trail in a new tab and it should display a grid of changes to the model instance. It should be empty right now, but if you execute actions on any of the Book instances, you should see the change history in the audit trail tab.
But how do we show the Create form for the book? To do this, we add a UI Meta Model entry for the WebAction:
... as well as for the WebActionRef ...
Make these changes, submit the MPT, reload the UI and create a new book to test it out.
Finally, you can make other actions available on your detail page. Try configuring the Action Screen's Detail View for the ZBKS.Publish action. This should make that action available on the detail page for books in the Proposed state.