<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Mattias Bomelin</title> <link>https://world.optimizely.com/blogs/mattias-bomelin/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Business Foundation field attributes</title>            <link>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/business-foundation-field-attributes/</link>            <description>
&lt;p&gt;Creating a meta field for a BF class of type string will by default result in a db column nvarchar(50). Changing the meta field type to LongText will result in the same.&lt;/p&gt;
&lt;p&gt;After consulting the documentation (read decompiler) we learn that an attribute is also needed to actually change the db column type.&lt;/p&gt;
&lt;p&gt;The MetaClass.CreateMetaField() function allows to input an AttributeCollection. Adding the attribute LongText with the value &amp;ldquo;true&amp;rdquo; to the collection will result in a db column of type ntext.&lt;/p&gt;
&lt;p&gt;It&#39;s also possible to use the properties from my previous post about validators as attributes when creating meta fields. The meta class validator XML will then be extended with the validation information from the attributes and some of them will also be used when createing the db column.&lt;br /&gt; For example using MaxLength for a string field type will change the default db column nvarchar(50) to nvarchar(x) as well as adding the MaxLength attribute to the validator XML.&lt;/p&gt;
&lt;p&gt;Some validator properties have inconsistent naming in the meta field creation process in case you&amp;rsquo;re wondering why not all validator properties work. For example the validator property &#39;ValidationExpression&#39; for File field types is represented in the meta field attributes as &#39;NameRegexPattern&#39;, and the validator property &#39;IsMultiValue&#39; is called &#39;MultiValue&#39; in the meta field attributes.&lt;/p&gt;
&lt;p&gt;Happy coding ;)&lt;/p&gt;
&lt;p&gt;Btw, I got questions on the image in my first blog post. It&#39;s from an old goat stable in the middle of nowhere in the northern parts of&amp;nbsp;Sweden.&lt;/p&gt;
&lt;p&gt;Being an e-commerce geek I think todays image is really fun. It was a delivery to me from a swedish office supplies company who didn&#39;t mind reusing boxes from their incoming deliveries (wonder where they&#39;ve hidden those in the catalog, I looked but couldn&#39;t find it). Even for a company within the &#39;adult&#39; segment, where one of the most common usp&#39;s is anonymous deliveries, it would be outrageous making a delivery like that!&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;/link/5339d54a669b43028ec80db6ecaff6d1.aspx&quot; alt=&quot;Image Bild(33).jpg&quot; /&gt;&lt;/p&gt;
</description>            <guid>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/business-foundation-field-attributes/</guid>            <pubDate>Thu, 19 May 2016 20:45:26 GMT</pubDate>           <category>Blog post</category></item><item> <title>Business Foundation Validators</title>            <link>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/business-foundation-validators/</link>            <description>&lt;p&gt;First off, what is Business Foundation (BF)?&lt;/p&gt;
&lt;p&gt;BF is basically a meta system where you can define an entity type and its properties. But it doesn&amp;rsquo;t stop there, the main differences between BF and the &amp;ldquo;regular&amp;rdquo; meta system in Commerce are that you can define relations between your meta classes, and that there&amp;rsquo;s a management UI you can extend and modify without changing any code. Sounds easy, but unfortunately not very well documented.&lt;/p&gt;
&lt;p&gt;The management UI basically consists of views for displaying the data and forms for editing the data. Whenever an entity is saved, using the UI or using the api&amp;rsquo;s, the data is validated using a set of configurable properties and validators. So why&amp;nbsp;implement you custom validation when it&#39;s right there in front of you, and used both by CM and all your application code.&lt;/p&gt;
&lt;p&gt;Every meta class is represented in the mcmd_MetaClass table where the class level data is stored.&lt;/p&gt;
&lt;p&gt;The field XSValidators contains XML data defining how the fields in a meta class should be validated. For each field you may define the validator implementation to use along with some validator specific properties.&lt;/p&gt;
&lt;p&gt;Below is a partial sample from the Contact meta class.&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;

&amp;lt;ArrayOfValidator xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.GuidFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;ContactId&quot; AllowNull=&quot;False&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.DateTimeFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;Created&quot; AllowNull=&quot;False&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.StringFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;FullName&quot; AllowNull=&quot;False&quot; MaxLength=&quot;200&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.EnumFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;CustomerGroup&quot; AllowNull=&quot;True&quot; EnumTypeName=&quot;ContactGroup&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.ReferenceFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;PreferredShippingAddressId&quot; AllowNull=&quot;True&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;nbsp; &amp;lt;Validator TypeName=&quot;Mediachase.BusinessFoundation.Data.BooleanFieldValidator, Mediachase.BusinessFoundation.Data&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Params FieldName=&quot;MyCustomBool&quot; AllowNull=&quot;True&quot; /&amp;gt;
&amp;nbsp; &amp;lt;/Validator&amp;gt;
&amp;lt;/ArrayOfValidator&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you see there are a variety of validator types, and not all properties can be managed in the Business Foundation management UI. Also, when setting up a large e-commerce project which might need deployments to several different environments we&#39;d like to automate the setup of these validators but that&#39;s another story.&lt;/p&gt;
&lt;p&gt;A&amp;nbsp;validator is defined using ntype names&amp;nbsp;and assemblies making it possible to create custom validators implementing IFieldValidator and IValidator. Yay :)&lt;/p&gt;
&lt;p&gt;But first, let&#39;s take a look at the existing validators.&lt;/p&gt;
&lt;p&gt;AllowNull is a parameter used in most validators and defines whether or not to accept a null value.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;StringFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This validator is used to validate a string input.&lt;/p&gt;
&lt;p&gt;Maxlength defines the maximum char length that may be input. Note that this is just a validator, make sure not to allow a string longer than you can actually store.&lt;/p&gt;
&lt;p&gt;RegexPattern is a nifty property where you can define a regular expression to validate the input against.&lt;/p&gt;
&lt;p&gt;For example, if you create a string field in the BF management UI and select the format &quot;e-mail&quot; the RegexPattern would be set to \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* which is in my opinion far too basic. Just pop in a new regex and you&#39;re all set :)&lt;/p&gt;
&lt;p&gt;Other use cases could be to validate phone numbers, postal codes, allowed chars for name fields and so on. Also, there is no MinValue property so you could easily use the regex property for validating your minimum string length.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GuidFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This validator is used to validate if the input is a valid guid. If the value can be parsed to a guid it&#39;s valid.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;BooleanFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value is of boolean type.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DateTimeFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value is of DateTime type, and checks the below properties if present.&lt;/p&gt;
&lt;p&gt;MinValue - can be used to set the lowest allowed value&lt;/p&gt;
&lt;p&gt;MaxValue - can be used to set the highest allowed value&lt;/p&gt;
&lt;p&gt;For birth dates MinValue and MaxValue could be used to limit how young or old contacts that may be created, or if we would store for example a member date we wouldn&#39;t want to have dates from before the member system was created. If you would like to disallow dates in the future you could create your own validator and add a property for enabling/disabling future date validation.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CurrencyFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value is of decimal type.&amp;nbsp;Not sure why it&#39;s been named CurrencyFieldValidator since it&#39;s just a basic decimal validator.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DecimalFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Works the same as the CurrencyFieldValidator but also has MinValue and MaxValue properties to limit the minimum and maximum value that may be entered.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DoubleFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Works the same as for decimal but validates if the value type is double. Also accepts MinValue and MaxValue.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IntegerFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Works the same as for decimal but validates if the value type is integer. Also accepts MinValue and MaxValue.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EnumFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value maps to a value in an enum meta field.&lt;/p&gt;
&lt;p&gt;EnumTypeName is used to define which meta field to compare the input value with.&lt;/p&gt;
&lt;p&gt;IsMultiValue defines whether or not multiple values may be input. If not accepting multiple values correct input type would be int or string, and for multiple values input types would be int[] and string[]&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FileFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value is of type FileInfo.&lt;/p&gt;
&lt;p&gt;ValidationExpression property allows you to specify a regex to validate the file name againts.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IdentifierFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This validator is a bit weird, it validates if the value is of type MetaIdentifierValue or of type string.&lt;/p&gt;
&lt;p&gt;If the type is string any value is valid which makes me confused of the use case.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ReferenceFieldValidator&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Validates if the value is a PrimaryKeyId&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>            <guid>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/business-foundation-validators/</guid>            <pubDate>Mon, 16 May 2016 09:53:42 GMT</pubDate>           <category>Blog post</category></item><item> <title>Hello world :D</title>            <link>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/hello-world-d/</link>            <description>&lt;p&gt;I guess I&#39;ve been too lazy, and had too little time, to blog but now I&#39;ve decided to grab the monkey by its ass or whatever the saying is. Having worked with web based applications since 1998, and e-commerce since 2001, I think I&#39;ve got alot of interesting challenges and experiences to share.&lt;/p&gt;
&lt;p&gt;Maybe you&#39;ve seen me on some meetup or event the past few years, if not maybe we&#39;ll meet next time. Whenever there&#39;s a party.... Jokes aside, with 3 small kids at home I can&#39;t attend all the happenings but I&#39;m at least trying :P&lt;/p&gt;
&lt;p&gt;During my time in the business I&#39;ve tried on a few different hats - developer, DBA (mainly Oracle and MySQL), infrastructure, server platforms (Linux since kernel 1.0.2, *BSD, Solaris, Windows), architect, CTO. On top of that I&#39;ve founded and run a couple of own business, some quite successful and some not so successful but hey, it&#39;s been a blast and I&#39;ve learned from it either way. &lt;br /&gt;I&#39;ve also been involved in a couple of startups, breaking new ground with techniques and applications not commonly used by web projects, and I&#39;ve also found it very stimulating to do whatever neccessary to get the project forward regardless of techniques what role is stated on your contract.&lt;/p&gt;
&lt;p&gt;My epi journey started in 2006 when I did my first CMS implementation. Wheter it was Sk&amp;aring;nemejerier or ProViva I can&#39;t remember. Since then I&#39;ve worked with epi every now and then, mixed with other platforms such as Litium, Magento and Umbraco. The past 3 years I&#39;ve focused 100% on epi for commerce implementations though, and in my current position as CTO at the e-commerce division at Knowit I face interesting epi commerce challenges daily so I guess I have the coming blog topics covered.&lt;/p&gt;
&lt;p&gt;Now the intro&#39;s done I guess, if there&#39;s anything you wonder or would like to comment please feel free.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/95f19bf77a304b4c84c45d57d24f002c.aspx&quot; alt=&quot;Image photo (1).jpg&quot; /&gt;&lt;/p&gt;</description>            <guid>https://world.optimizely.com/blogs/mattias-bomelin/dates/2016/5/hello-world-d/</guid>            <pubDate>Mon, 02 May 2016 11:44:03 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>