Can We Have Custom Data Type In BizTalk





Well I got this question when I had to have data in some specific pattern.


A very common field is email address where we want it in particular and valid pattern, e.g., “myemail@mydomain.com”

So here is the pattern I used :   \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

In my case along with the email field  it was the field called “fileExtension”, and the only extension which was valid as per requirement where  .txt , .pdf , .xsl ,.xslx,.doc and .docx  etc.

So here is the pattern I used : ^.*\.(txt|TXT|xsl|XSL|xslx|XSLX|doc|DOC|docx|DOCX|pdf|PDF)$


Note: 

You can add other extensions too if you need it, in my case above mentioned ones were the only required.


Steps to make it happen (Here I am using email as example):

1.      Open the schema in BizTalk Schema Editor
2.      Select the element on  which you want to set the desired data pattern
3.      Go to properties window.
4.      Set the Base Data type as xs:string
5.      Set the ‘Derived By’ property to ‘Restriction’.
6.      Select ‘Pattern’ property and click the ellipsis
7.      Type the regular expression(s) in the ‘Pattern’ property

Pattern Editor



properties window




8.      I had element under other records in same schema which will have email as value, thus I wanted to have same pattern included for those also.

9.      Did following:

i. I added text “emailType” on the property filed “ Data_type” and this creates  new simple type.

ii. I used on all the other elements on which you want same validation or want it to have data in same      form then select its base data type as "emailType"

10.      In below figure , I am using “emailType” as Data Type. (AddLine2 is used for holding secondary email)


Datatype properties window




11.      All done but does it really work? I tested with passing a instance having incorrect email id:
       
As expected , it erred out:

error BEC2004: The 'Email' element is invalid - The value 'myemailgmail.com' is invalid according to its datatype 'http://Process_Schemas.CommonAddress:emailType' - The Pattern constraint failed.
error BEC2004: Validate Instance failed for schema CommonAddress.xsd, file:

12.      When tried with correct email, it was success:

Invoking component...
Validate Instance succeeded for schema CommonAddress.xsd, file:       <file:///D:\Biztalk\MyProjects\Process\addressSampleInstance.xml>.
Component invocation succeeded.



So this is how I was able to create custom data type “emailType” and did follow same for the other custom data type “extensionType”.




If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!




1 Comments

If you have any suggestions or questions or want to share something then please drop a comment

  1. Like that above process how to remove date minus symbol(-)example 1990-05-10 to 19900510 that both schema type is date only

    ReplyDelete
Previous Post Next Post