Embedding error code definitions in Xslt files

Just as you can embed error code definitions in custom Link3 assembly artifacts (e.g. itinerary steps) from which they will automatically be registered in Link when the artifact is deployed, you can do the same with Xslt artifacts.

If you have an Xslt map which needs to throw a specific kind of error under specific circumstances, it is better to have the error code definition in the Xslt itself, otherwise you have to remember to create the error code definition manually in Link when you deploy the map to a new server. Just remember that if a given error code is defined in an Xslt, it cannot be edited directly in Link. Any changes to the error code definition will have to be done in the Xslt, and then it has to be redeployed.

In order to embed an error code definition in an Xslt file, all you have to do is to add one or more (if you have different types of error) specific Xml structures to the Xslt, directly under the root node.

You can write the Xml by hand if you so wish, but to make it easier to do (and to prevent typos and such) there is a NuGet package (Bizbrains.Link.Schemas.ErrorCodes) you can add to your project, if you edit the Xslt in Visual Studio:

Error code schema NuGet package.png

 

The NuGet package adds a reference to the Xml schema defining the error code definition structure to your project. At this point you can add a prefix registration of the schema’s namespace to your Xslt like this:

Error code schema namespace.png

 

This enables Visual Studio to recognize the error code definition structure, and to offer autocomplete help with writing it:

 

The autocomplete functionality is not limited to the structure itself, it also helps with assigning values to the fields which are enumerations:

 

The final structure looks like this:

<loc:LinkErrorCode> <loc:ErrorCode>9YJDP</loc:ErrorCode> <loc:ExceptionCategory>DataValidationError</loc:ExceptionCategory> <loc:ExceptionTypeArea>Itinerary</loc:ExceptionTypeArea> <loc:Component>LinkErrorCodeTest.xslt</loc:Component> <loc:ExceptionCause>The document contains no sender information.</loc:ExceptionCause> <loc:ExceptionSolution>Contact the sender to let them know the SenderID is mandatory for this document type.</loc:ExceptionSolution> <loc:TechnicalDescription>This field is optional.</loc:TechnicalDescription> </loc:LinkErrorCode>

You can embed as many error code definitions in the Xslt as you like. As always though, remember to generate the error codes themselves through the UI using the “Generate code” option on the page Developer->Error codes. This guarantees you that the code is not already in use on the system.

 

The information on this page is based on Link 3.00