PowerShell Connector Import All Operation
The Import All operation imports all entities from the target system. Each of these entities need to be represented with the data in the target system.
For this example, student data is being retrieved from a particular table in a database. Each student has a:
- and PhoneNumbers
Which each correspond to a particular field in the table. The values in each entity are described by the connector schema.
In this example the schema will be:
New-Field "UniqueIdentifier" "int" $true $false $false New-Field "FirstName" "string" $false $false $false New-Field "LastName" "string" $false $false $false New-Field "EmailAddress" "string" $false $false $false New-Field "YearLevel" "int" $false $false $false New-Field "PhoneNumbers" "string.multi" $false $false $false
The PowerShell import all script should then request all of the student information in the database, and give UNIFYBroker a series of entities that represent the data.
Entities are presented to UNIFYBroker by first creating them, populating them with data and then finally committing them.
We can achieve all of the above with the following code:
$entity = $entities.Create(); # Create the entity $entity['UniqueIdentifier'] = 1; $entity['FirstName'] = 'Jim'; $entity['LastName'] = 'Car'; $entity['Email'] = 'email@example.com'; $entity['YearLevel'] = 5; $entity['PhoneNumbers'] = @('0400 0000', '3800 0000'); # Populate it with data $entity.Commit(); # Commit the entity
Values provided in to the field do not necessarily need to be of the same type as the schema. For instance, a string
"1" could be provided to an integer field and it will be converted to the integer 1.
One entity should be created for each instance of an object in the target system, so for the example of a Students table, one entity should be created for each student.
.Commit()will not be imported, and removed from the connector if they already exists from previous imports. For this reason, avoid using
exitstatements or methods of ending script execution without an exception and ensure failures are handled as described in PowerShell Connector Failed Operations.
Customer support service by UserEcho