XSLT Function LookupOrCreate

This function works the same way as LookupValue but in case nothing is found it will create the missing record. This is useful for integration and ETL projects where you can simplify the data import scripts.




string LookupOrCreate(string lookupElementId, string parameterValue, NodeSet createParameters)


Name Description
lookupId Unique identifier (Guid) of lookup model element
parameterValue Value to lookup by (that the lookup’s data structure will use as a filter parameter).
createParameters Key-value pairs providing data for a new record (in case it does not exist).


This function uses the ListDataStructure entity of the lookup for creating the record. For this you will need to set AllFields to True so the data will be safely inserted to the database. This is mandatory. Primary key and other system fields (creation time and user) will be filled in automatically.


You should use this function carefully as it writes data during transformations. Especially be careful when state-machines exist on the entity being written to. For a sake of simplicity you should mainly use this function for inserting missing records into simple lists e.g. while importing data from external data sources.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="AS date">
    <xsl:template match="ROOT">
        <!-- we are trying to get an airline id by its code -->
        <xsl:variable name="code" select="'OA'"/>
	        <!-- if not found we let it to be created -->
            <xsl:variable name="valueParams">
                <parameter key="Name" value="Origam Air"/>
                <parameter key="IataCode" value="{$code}"/>
		        <!-- this single function will then always return a value -->
                <xsl:value-of select="AS:LookupOrCreate('3abe98c3-e3b1-4960-b426-1f69532f8cd0', $code, $valueParams)"/>