Sitecore tips and tricks and community news !

Post Top Ad

Post Top Ad

Showing posts with label Add. Show all posts
Showing posts with label Add. Show all posts
7:37 PM

WFFM Action add contact to contacts list, extend conditions

All of us know WFFM very well and made there a lot of things. We would like today focus on particular action - "Add Contact To Contact List"

In general, this action is used to adding some contact data gathered from form and push this information as a contact to some list in List Manager. More details information is available in documentation here.

This action has very useful things - conditions:


It provides ability to create conditions based on fields you have in your form to add contact to the list. Developer see list of checkboxes what is userfriendly. 

List of checkboxes works as an 'OR' condition, so first true statement return true for whole list.

What in case when we want to have 'AND' condition and check if all selected checkboxes give true? Is it possible?

Sure, it is ! :)

I had already custom action which has been inherited from default action "Add Contact To Contact List". If you don't have this situation it's good to make it in this same way.

When we decompile this action we see:


Highlighted area on red show us part of code responsible for checking our conditions. To change it we have to take a look how it's working currently and how we can change it. Hence, during digging we see:





Selected area shows exactly, when some condition return true, the whole method return true as well. Right now, we have to think how to change it to AND condition ? I propose to create an array of results per each condition, then check if all of them return true. Since we will have that information we can decide if whole method should return true or false.





Later we have to only use our method implementation in our custom action. That's all ! It's working perfectly :)

Make conditions in that way and give content editors more possibilities :)

10:00 AM

Dynamic insert options

Insert options, everybody know what does mean :) This is the place where we can make content editor life happier. We can prepare options in Content Editor context menu, to add new item based on some dedicated template.
It looks like image below.



Ok, so we have insert option, we have even put there some our custom template to create datasources. But what if we want to have only one instance of this item in this particular place ? Insert option allows to put as many we can, it doesn't say "Mate, only one is possible here". Is it possible to do that?

Well, yes it is :)

To make this dynamic option, we will use Rule Engine in Sitecore!

1. Rules for Insert Options.

To find rules we have to go to the path:

 /sitecore/system/Settings/Rules/Insert Options/Rules 

 In that place we can find something looks like:


To create new item, just click on Rules parent item and chose "Insert Option Rule". When we create this item, we can go to the field "Rule" and click it. This action will open a dialog when we can build our custom rule.


2. Rules Queries

Rules can as custom as we want. Only constraint can be your imagination. In our case it will be condition, if item (as an instance of our template) has been already added to this particular place, or not. To do that we can write query like:


Voilà, we have dynamic insert option in our application and new friends in content editor team :)