Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > MACROS(replace) View modes: 
User avatar
Member
Member
luyolo.mhlauli-nmmu.ac - 8/26/2011 9:38:32 AM
   
MACROS(replace)
I have added two fields in my Home page form called

MenuItemContacts and MenuPageWhere

What is stored in the field MenuItemContacts = luyolo;mhlauli

What is stored in the field MenuPageWhere = 'AND Username ='

In this HomePage there is a userviews wepbart

I have set the WHERE condition of WepPart to

UserName='{%replace(CurrentDocument.MenuItemContacts, ";", "{(2)%CurrentDocument.MenuPageWhere%(2)}")%}'

In order to get UserName = 'luyolo AND UserName = 'mhlauli'

They Web Part returns no data.Is there any other way I can do this

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/27/2011 7:39:09 AM
   
RE:MACROS(replace)
Hi,

could you please provide some background of your requirement?

What should be displayed by web part? Unfortunately, your condition does not make sense to me. The username cannot have two values in the same time. The OR condition would make more sense, but not sure.

Is you requirment to display profile of 2 users whose usernames are in MenuItemContacts property?

In that case please replace AND with OR operator and add a space at the beginning:

' OR Username ='

But the macro will not be resolved correctly.

Would it be possible for you to store userIDs instead of usernames? Then you could create a condition without apostrophe, i.e. you could use a custom macro that will parse userIDs string a create a where condition which should select appropriate users for the web part.

How to create a custom macro is described here:
http://devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm

The value of form tab fields will be accessible in the macro using CMSContext.CurrentDocument.GetValue("FieldCodeName")

Best regards,
Ivana Tomanickova

User avatar
Member
Member
luyolo.mhlauli-nmmu.ac - 8/29/2011 1:55:42 AM
   
RE:MACROS(replace)
The webpart will display users who were selected using the multiple user selector(MenuItemContacts). MenuItemContacts is a field added to the Page(MenuItem) document type and its field type is of multiple user selector. so when you use it you will have a list of users then you will tick on the checkbox next to the user this means if you select two users who are ivan and luyolo the field stores ivan;luyolo so I wanted to change it to Ivan' OR Username ='luyolo.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/30/2011 4:48:03 AM
   
RE:MACROS(replace)
Hi,

you could use following Where condition:
username in ('{%MenuItemContacts|(replace);(with)', '%}')

it will create string which should select appropriate users.
username in ('Andy', 'editor1')

The issue here is tha ' cannot be returned by macro for security reasons. You may need to clone web part as described in this furum and set this.SQLProperties = "";

Alternative solution is to use multiple choice control instead of multiple user selector. It has an option to define custom query to select data. You can select userID and userName so that value will be userID.

Then you can use following where condition:

userID in ({%MenuItemContacts|(replace);(with), %})

Best regards,
Ivana Tomanickova

User avatar
Member
Member
luyolo.mhlauli-nmmu.ac - 8/30/2011 7:35:25 AM
   
RE:MACROS(replace)
Hi Ivana

I did manage to sort it out yesterday using a custom macro in the where condition and yes I had to set this.SQLProperties = "" in the cloned WebPart.