UI Refresh script

A UI refresh script can be defined for a container (catalog or hierarchy). The script operates with a Refresh button on the single-edit and multi-edit pages of the interface.

After you click Refresh, the following steps occur:
  1. On the client, takes all the changes that are made and sends them to the server.
  2. On the server, for each entry in the set,
    • Retrieve the current copy of the item from the database.
    • Apply the Entry Build script.
    • Apply the pending changes that are transferred from the client.
    • Apply the Default Value rules and the Non-persisted Value rules.
    • Apply the UI Refresh script.
    • Add the updated entry to a set to be sent to the client.
  3. On the server, return the set of updated entries to the client.
  4. On the client, render the data on the screen.
For single-edit, the set of entries is the entry that is being edited. For multi-edit, the set of entries is those that are currently selected. The UI refresh script runs after all of the other scripts and thus, all the attributes have most current values.

In single edit, the UI Refresh script is applied to the displayed entry where any attribute's value changed. In multi-edit, the Refresh is disabled unless a row is selected, and the UI Refresh script is applied only to selected entries (rows), where they contain attributes whose values changed, and in the order of those rows from descending order.

Specifying the UI Refresh script

You can define a UI Refresh script for a container. To do so, you must upload the text of the script to the docstore, through a specific directory and a script name of your choice, and define the script name to the container. For a catalog, the directory is /scripts/catalog and for a hierarchy it is /scripts/category_tree. To define the script name to the container, use the script operation setContainerAttribute with the key UI_REFRESH_SCRIPT_NAME, and specify the name but not the directory, as illustrated in the following example script (where the script name is ui_refresh.wpcs):
var container = getCtgByName("CATALOG");
var attrs = [];
attrs.add("ui_refresh.wpcs");
container.setContainerAttribute("UI_REFRESH_SCRIPT_NAME", attrs);
container.saveCatalog();

Refresh script contents

A UI refresh script can contain any script operations. The entry on which script operates is available through the implicit variable entry, and in general the set of implicit variables is the same as that for a Post-save script.

If a UI refresh script is used to change the values of attributes in the entry, the order of those changes is completely under the control of the script's author. If the transitive dependencies (attribute A depends on attribute B, which depends on attribute C) the changes must be done in the correct order (in this example, C, then B followed by A).

Example script for a catalog that is defined with spec that has two String attributes A and B:
var val_B = entry.getEntryAttrib("spec/B");
entry.setEntryAttrib("spec/A", "The value of B is: " + val_B);