The Adopt Fields->Custom menu facilitates the development of custom scripts to manipulate individual links in the current document.
The dialog displays the active documents links on the left, and the links after processing by the script. Pressing the Test button will execute the code for each link and present the results in the right hand column.
The code is called once for every link, with variables passed which represent the individual elements a link:
On exit the values of these variables are assigned to the link.
Each element of the link is color coded to show validity, with green valid and red invalid. All green icons indicate the link can be matched to a a field in the current data source.
Saving Scripts To the Adopt Fields Menu
Custom adoption can be used as a regular part of a workflow, and as such scripts can be added to the “Adopt Fields” menu. Selecting “Save..” on the popup at the bottom of a dialog will prompt for a name. This is then permanently added to the menu for the current data source. These are stored inside the Scripts folder inside the Data source folder and can be removed manually.
Here’s a simple example of a script that replaces the key element of a link:
ds = DATASOURCE.get(datasource);
-- find the record that matches the links key to the contents of the "KeyID" field
rs = ds:getrecordset():filter("KeyID", key);
if rs:size() > 0 then
-- Replace the key value with the contents of the "SKU" field
key = rs:getrecord(1):field("SKU"):content();