Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > User Selector View modes: 
User avatar
Member
Member
Chanan - 4/2/2011 7:18:38 AM
   
User Selector
Since the user selector works off of UserId instead of UserGuid it causes some problems when used with Content Staging. The UserId field is auto numbered, so a UserId on the staging server may not be the same as the production server.

User avatar
Member
Member
Chanan - 4/12/2011 9:18:20 AM
   
RE:User Selector
Are there any ideas on how to get around this problem where the UserIDs are not the same between our Dev, Staging and productions servers? Should we get rid of this field and manually enter username instead?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/12/2011 11:42:46 AM
   
RE:User Selector
Hi,

If you are storing reference for User object in your custom object (document type or other), that is probably going to be transferred using content staging, it's of course advisable to use other identifier than UserID. It is translated only for system default objects.

You don't need to enter the user manually, however modifying the User selector form control may be needed.

You can make a cloned copy of the default one - code in ~\CMSModules\Membership\FormControls\Users\SelectUser.ascx


and set ReturnColumnName property to "username" like:
...
<cms:UniSelector ID="usUsers" runat="server" ObjectType="cms.user" SelectionMode="SingleTextBox" AllowEditTextBox="false" ReturnColumnName="username" />
...
You can also use UserGUID column.

Then you can register it in Site manager -> Development-> Form controls and use it.

In version 6, user selector returns UserName by default.

Regards,
Zdenek

User avatar
Member
Member
Chanan - 4/12/2011 12:11:23 PM
   
RE:User Selector
How do you store GUID in a custom type? It's not one of the Attribute Types in the drop down.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/12/2011 2:04:46 PM
   
RE:User Selector
Regrettably the field of type "unique identifier (GUID)" is not supported for usage in document type fields. It's only available for system and custom tables.

You can optionally store GUID as text value in field of type 'text'. It's length is 36 chars...

--Zdenek

User avatar
Member
Member
jhoppe - 4/15/2011 11:21:49 AM
   
RE:User Selector
We've customized the form control. The form is percent encoding the data when storing it in the database - the @ sign in particular. Can we configure this?

Also, the form is not selecting the user when we pull up a document with the value already set. How can I set it to select the current document?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/18/2011 5:23:44 AM
   
RE:User Selector
Hi,

Am I understanding it right that you're using above described approach to store user name or GUID?
Which form control have you customized? What was the change?

The encoding performed is URL encoding? The code of the form control determines what is returned...
More details would be appreciated.

--Zdenek

User avatar
Member
Member
jhoppe - 4/18/2011 8:41:08 AM
   
RE:User Selector
Zdenek,

We decided not to store user name or GUID, but instead email address, since it is our unique identifier.

I've copied ~\CMSModules\Membership\FormControls\Users\SelectUser.ascx to ~\[SiteName]\FormControls\SelectUserCustom.ascx, setting ReturnColumnName property to email address:

<cms:UniSelector ID="usUsers" runat="server" ObjectType="cms.user" SelectionMode="SingleTextBox" AllowEditTextBox="false" ReturnColumnName="Email" />


I then registered it in Kentico as a form control, and set the custom document type's field type to the new form control.

When I go into a document in the CMS Desk form tab, I can see the control and can select a user. After saving the document, I can see in the database that the database field's value is abc%40test.com, when it should instead display an '@' sign in place of the %40.

How can I prevent this behavior?

Second, when I open the form tab of the document, the new user selector's text box is always blank. I would like to have it populate the text box based on the current user email address in the database field. Do you happen to know why it does not? It does not populate the field, regardless of whether the user's email address is correct (i.e. abc@test.com) or if is HTML encoded.

Thanks!

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/20/2011 9:37:42 AM
   
RE:User Selector
Hi,

It's url-encoded in ~\CMSAdminControls\UI\UniSelector\Controls\SelectionDialog.ascx.cs in GetSafe method.
This shouldn't be changed because the control is used in more places.

You can use reverse approach in your customized form control in
public override object Value / get method, where you can decode the result using Server.UrlDecode method.

As for automatic value in the Form tab - you can check the control Value for emptiness in Page_Load of your form control and optionally set the Value with using CMSHelper.CMSContext.CurrentUser.UserEmail property.

--Zdenek

User avatar
Member
Member
joeh42 - 5/9/2011 1:19:00 PM
   
RE:User Selector
Zdenek,

I decided to store GUID in the database in case users change their email addresses. This field tracks who is considered the submitter of a custom document on our site in the table of the custom document.

However, if users search for a person's name on the site, the search index does not tie the user's name into the content, so the custom documents aren't retrieved as search results.

I then hoped to modify my custom form control SelectUserCustom.ascx, such that when someone selects a user and saves the document, it will update the GUID but also a second field SubmittedByUserFullName.

This seems like its stretching the design of the custom form control. Is this possible?

I attempted to sneak some code into the override of Value, which works, but unfortunately when the document gets published, the database field gets overwritten.

Your responses have been very helpful.

Thanks,
Joe



public override object Value
{
...
set
{
EnsureChildControls();
usUsers.Value = value;
SubmittedByUserFullName();
}
}

private bool SubmittedByUserFullName()
{
UserInfo userInfo = UserInfoProvider.GetUserInfoByGUID(new Guid(this.Value.ToString()));
if (userInfo != null)
{
// tree provider
CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);

// get document with specified site, alias path and culture
CMS.TreeEngine.TreeNode node = provider.SelectSingleNode(Convert.ToInt32(Request.QueryString["nodeid"]));

if (node != null)
{
node.SetValue("SubmittedByUserFullName", userInfo.FullName);
node.Update();
return true;
}
}

return false;
}

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 5/23/2011 9:41:49 AM
   
RE:User Selector
Hi Joe,

It's generally not wrong to extend functionality of a form control so that it stores an extra information in separate field, so it's ok.

An altenative way would be to use Custom TreeNode handlers (http://devnet.kentico.com/docs/devguide/treenode_handler.htm).

Anyway, in your case, the solution and explanation is quite straightforward:

1) It's better to perform any field setting in Form Control's Value GET method, because that is called when the form is being saved. Set method is for filling the control when the form is loaded for existing document.

2) Your code doesn't work when publishing the document, because under workflow, you cannot use this approach and SelectSingleNode - see details in API reference on Workflows and versioning / Working with the versioned documents

3) It's not necessary to select the node twice, since you have access to the document that's being edited.
The best example of code that you'll need in your custom form control can be found in

~\CMSModules\Content\FormControls\Tags\TagSelector.ascx.cs

in GroupId property GET method:

public int GroupId
{
get

there are two branches for state when new document is being created or when an existing one is being edited, to simplify, the most important code lines (accessing the node's NodeAliasPath property) are:

for insterting new doc:
((TreeNode)this.Form.ParentObject).NodeAliasPath

for editing existing doc:
((TreeNode)this.Form.EditedObject).NodeAliasPath

You can copy and modify whole branch starting with

if ((mGroupId == 0) && (this.Form != null))
{

... where you only need to check the second condition (that Form is not null).

So, I believe it should be enough to use this approach instead of your code, set the node's property and let the form engine save the document with the modified custom field value automatically. You won't need to worry about workflow or call Update method... it should just simply work.

Hope this helps.

Regards,
Zdenek

User avatar
Member
Member
joeh42 - 6/10/2011 9:48:06 AM
   
RE:User Selector
I see that you state that the node is already selected, but which object is it?

I tried all of the commented out calls in the section below, but I'm not sure what object I can use to update the custom document property.

I also tried to select the node again, as I've done in my previous snippet, but the engine doesn't seem to like that.

I was updating an existing document for my test case.

Thanks!!!


public override object Value
{
get
{
if (this.Form != null)
{
string path = "";

// When inserting new document
if (this.Form.ParentObject != null)
{
...
// When editing existing document
else if (this.Form.EditedObject != null)
{
string fullName = UserInfoProvider.GetUserInfoByGUID(new Guid(usUsers.Value.ToString())).FullName;
//((CMS.TreeEngine.TreeNode)this.Form.ParentObject).SetValue("SubmittedByUserFullName", fullName);
//SetValue("SubmittedByUserFullName", fullName);
//usUsers.SetValue("SubmittedByUserFullName", fullName);

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 6/26/2011 7:49:22 PM
   
RE:User Selector
Hi,

The object is either known a ParentObject or EditedObject, when one of those is not null, you assume that the object is a TreeNode:

(TreeNode)this.Form.ParentObject (or EditedObject)

Do you receive any error when you call SetValue method on that TreeNode object?
How have you tried to select the node again? What does the engine report?

Thanks for info,
Zdenek