Using Custom entities you can store and use custom lookups whose data lives, for example, in other systems (applications). You can refresh lookup data with script automation that runs on a schedule or manually.
In this example we work with a custom entity whose attributes are already configured.
In the project settings, under Custom Actions, create a new action for this custom entity:
As a parameter, specify an XML field of type "text field", and select the option that this custom action is used to create lookup rows.
On the PHP Script tab, place a script that parses the passed XML and creates lookup rows from the XML data:
$doc = new \DOMDocument("1.0", APP_ENCODING);
$doc->loadXML($it->get('xml'));
$text = "";
foreach(libxml_get_errors() as $error) {
$text .= $error->message;
}
if ( $text != '' ) getFactory()->error($text);
$custom = getFactory()->getObject('custom_ChangeNotifications');
foreach ($doc->firstChild->childNodes as $child)
{
if (! $child instanceof \DOMElement) continue;
getFactory()->mergeEntity($custom, [
'Caption' => $child->getAttribute("Caption"),
'Author' => $child->getAttribute("Author"),
'MainCode' => $child->getAttribute("UniqueIdentifier")
],
['MainCode']
);
}
the following is assumed:
Open the custom lookup and run the custom action:
In the event log you can track the lookup update history and problems that may occur while the script runs.