Using business keys in XMLs

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Bizagi from external applications > Bizagi API > SOAP web services > Requisites and concepts for SOAP web services >

Using business keys in XMLs

Overview

When using the Web services of Bizagi API (SOA Layer) from an external application, you may want to rely on unique codes to ensure that both Bizagi and your external application is talking about a given, same specific record.

Unique codes are managed by Bizagi through the business keys concept; and through it, you may link new information to an existing record in Bizagi or update these values when invoking Bizagi API as well.

 

It is a best practice to predefine business keys for those entities of your data model in which this concept is applicable.

 

BusinessKeys01

 

 

To view more information on how to do this for your entities, refer to Business keys.

 

How to reference existing records

When having predefined business keys for your entities (as recommended and shown above), you do not need to worry about whether a record already exists or not, and you may send the information within the XML so that it uses such definition to link to that particular record if it does exist.

For this, you would only need to ensure you include all the attributes of your entity which define the business key, as elements in your data model's XML.

 

In the following example, we part from having already defined DocumentNumber and DocumentType as the business keys for the Customer entity.

Data will be updated for that customer having Document type=1 AND Document number=123456789.

Only if that customer does not exist, then a new record will be created with the information supplied:

 

 

BusinessKeys03

 

 

Alternative for entities without a predefined business key

There is an alternative when no predefined business keys have been set at a given entity (or can't be set in an existing production environment): you may choose to include the businessKey clause as an XML attribute.

The syntax to use this attribute is as follows:

<[MyEntity] businessKey="[MyBusinessKeyAttribute]=[BusinessKeyValue]">

</[MyEntity]>

 

Consider:

[MyEntity]: Is the exact name of the entity does not have a predefined business key.

[MyBusinessKeyAttribute]: Is the exact name of the attribute which should be the business key.

[BusinessKeyValue]: Has the value that uniquely identifies the given record. Keep in mind that it should include quotes if referencing a string-type attribute.

When having a compound businessKey definition, use AND to separate attributes. For example:

businessKey="[MyBusinessKeyAttribute1]=[BusinessKeyValue1] AND [MyBusinessKeyAttribute2]=[BusinessKeyValue2]"

 

BusinessKeys04

 

Keep in mind that you may not update information directly held in attributes which make part of the business key.

Important

You should NOT use both definitions simultaneously (the definition at the entity along with a businessKey clause at the XML), and recall that predefining business keys for entities through Bizagi Studio is the recommended practice.

Predefined business keys on entities help you work with information controlled within the business itself (such as: codes, series numbers, numbers of identification, etc), and avoid using surrogate keys which are mainly for Bizagi internal purposes).