Tim Bond

I am tearing my hair out with this. I thought site terms were obvious but...

In Commerce server manager a site term value consistes of a Term name and a display name. This corresponds to XML attributes name and displayname in the SiteTerms.xml. So far so good.

When we get into .Net we ask for the SiteTerms objects Elements property and we get a collection of SiteTermElements. Each SiteTermElement has a Name property and a Value property. The documentation for these properties needs some attention. In the properties page it says:

Property Description
Name Accesses the name of the site term element
Value Accesses the value of the site term element

On the pages that these link to

Name is defined as:

A System.String containing the name of the site term element.

Value is defined as:

A System.Object containing the name of the site term element.

So the first thing to say is that according to the Visual Studio Object browser both of these properties return strings. The second thing that comes to mind is which is which Which is the displayname and which is the name. My intuition was the name was the name and value was the displayname but a bit of debugging quickly reveals that it is the other way around. So my new documentation says:

Property Description
Name Accesses the displayname of the site term value
Value

Accesses the term name of the site term value

So far I don't really have a problem the names are not the way I expected but I can work with that. Where I get the real problem is when the site terms have non unique displaynames. In our particular case we have geographic regions as state terms. Specifically "GE" - "Georgia" and "US-GA" - "Georgia". The CSManager is quite happy to allow multiple term names to have the same displayname but not the other way around. In DB terms the term name is the unique key.

Now what happens when we get into .Net land again. I expected to get two site term elements one for the country and one for the State. Instead I get one element the name is "Georgia" and the value is "GE,US-GA". My interpretation of what has happened here is that the code is treating name as a 'key' field and when it finds two elements with the same key it combines the values into a single comma seperated string. It sounds alright in isolation but it is WRONG. The problem is that the key has moved from one property to the other and this changes the semantics.

If I had to guess I would say there was a bug in reading site terms into .Net and the properties should be reversed. Then Name would correspond to Name and it would be unique in both .Net and CS manager worlds. Display name would correspond to Value and would not be unique in either world.

This is clearly a bug to me but I might be biased. At the very least a little documentation here would help. Has anyone else tripped over this Have I just missed an obvious explanation Is there anything else I can do to save others the grief I have suffered



Re: Commerce Server 2007 Issues with Site Terms

Jeff Lynch - MVP

Tim,

I think I understand your issue and here is how I found my way around this, which I "believe" is caused by how CS2007 stores Site Terms as COM+ dictionary objects just as CS2002 did. Converting this into something usefull in the ASP.NET 2.0 world is difficult which is why CS2007 uses the "SiteTermElementCollection".

I have a custom Site Term called "user_role". I use the method shown below to return a SiteTermElementCollection which contains the name/value pairs.

[DataObjectMethod(DataObjectMethodType.Select)]

public SiteTermElementCollection GetUserRoles()

{

// Get the SiteTermElementCollection for data binding on the site

return CommerceContext.Current.ProfileSystem.GetSiteTerm("user_role").Elements;

}

I use this method to feed an ObjectDataSource in my web code as shown below.

<asp:ObjectDataSource ID="UserRolesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetUserRoles" TypeName="UserManager"></asp:ObjectDataSource>

I then bind this to a DropDownList control as shown here.

<asp:DropDownList ID="UserRoleDropDownList" DataSourceID="UserRolesDataSource" DataTextField="Name" DataValueField="Value" runat="server" TabIndex="8"></asp:DropDownList>

The secret is to set the DropDownList's "DataTextField" attribute to "Name" and the "DataValueField" to "Value".

If I've missed what your issue is, I apologize. If not, then this type of code may help in your situation.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch






Re: Commerce Server 2007 Issues with Site Terms

Tim Bond

Thanks for the reply. It doesn't really solve my problem but is does help to explain why the Name property holds the displayname and the Value holds the term name.

I would be interested in your opinion of the results if you create 2 user roles that have the same displayname. Do you get 2 entries in the menu Do you get a valid siteterm name back from the menu or is it a composition of the 2 distinct roles.





Re: Commerce Server 2007 Issues with Site Terms

Jeff Lynch - MVP

Tim,

I apologize for neglecting this thread.

You can setup a Site Term (Term name, Display name) where the "Display name" <name> has already been used. Only the "Term name" <value> must be unique. In my code, the dropdown would contain three entries and two would be the same and this would confuse the user.

Think of Site Terms as <name, value> dictionary objects and it begins to make more sense.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch






Re: Commerce Server 2007 Issues with Site Terms

Tim Bond

I have been thinking of them as dictionary objects but the whole problem is that they don't behave like them

If I create three items with unique keys but two have the same display value then if I iterate through them I get two items one has the key being a concatenation of the two keys - that is NOT like a dictionary.

I am using this code to do the iteration:

SiteTerm siteTerm = MscsContext.ProfileSystem.GetSiteTerm(siteTermName);
if (siteTerm != null)
{
foreach (SiteTermElement element in siteTerm.Elements)
{
xxxx;

}
return elements;
}

Thanks for helping out with this. I have worked around this now but this seems like a bug to me and I would like someone to understand and maybe verify it as a bug.

Thanks Tim





Re: Commerce Server 2007 Issues with Site Terms

Jeff Lynch - MVP

Tim,

I did a quick experiment and added another term to our "user_role" site term so that we now have three entries, two which are completely unique and one in which the "Display Name" is duplicated as shown below.

Term name Display name

------------ -------------------

Admin Administrator

Normal Normal User

Test Administrator

When I run this code in debug mode it returns some interesting results which really do look like a BUG!

CommerceContext.Current.ProfileSystem.GetSiteTerm("user_role").Elements;

The "Term name" key returns three results as you would expect but the "Display name" key returns only two results. It looks like the Term name AND Display name keys must both be unique for the code to work correctly, even though the Commerce Server manager UI allows you to enter an non-unique "Display name".

Perhaps someone from the team can pick up on this thread and log a (potential) bug for the next service pack.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch






Re: Commerce Server 2007 Issues with Site Terms

J Beaulieu - CS Product Team

Tim and Jeff, I'm attempting to replicate this behavior and have a couple of questions:

1) Are either of you using the SP1 version of the Commerce Server Business Applications
2) Are you creating new Site Terms or adding another element to an existing site term

I've tried both approaches and the Customer and Orders Manager UI disallows the creation of site terms and site term elements where there's an existing element with the same name or display name.

Any additional information you could provide would be greatly appreciated. Thanks.

-jb




Re: Commerce Server 2007 Issues with Site Terms

Jeff Lynch - MVP

I am using CS2007 SP1 and the SP1 version of the Business Apps.

The site term is "new" and I added it using the Commerce Server Manager not the Customer & Orders Manager app.

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch






Re: Commerce Server 2007 Issues with Site Terms

J Beaulieu - CS Product Team

Jeff Lynch - MVP wrote:

I added it using the Commerce Server Manager not the Customer & Orders Manager app.



There's the piece I missed. Cheers.

-jb




Re: Commerce Server 2007 Issues with Site Terms

J Beaulieu - CS Product Team

Just wanted to give you both a heads up that this has been logged as a bug.
Cheers.

-jb