Microsoft KB Archive/280721

= Multi-Valued Site Term Properties in Commerce 2000 Profiles =

Article ID: 280721

Article Last Modified on 11/4/2002

-

APPLIES TO


 * Microsoft Commerce Server 2000 Standard Edition

-



This article was previously published under Q280721



SUMMARY
The Business Desk, which ships with the solution sites for Commerce Server 2000, does not support the use of multi-valued site terms for properties in a profile. Although you can set a profile's type attribute to Site Term and select the Multi-Valued attribute in the Profile Designer, you cannot activate these attributes. As a result, these attributes are not available in the Business Desk.



MORE INFORMATION
When a property in a profile has its attribute type set to Site Term, the values that are assigned to this property must come from the Site Term that is selected in the Type Reference attribute for the property.

Many property types, such as the string property, allow you to assign and edit multiple values for profile properties in the Business Desk. However, this functionality is not available for Site Term properties in the Business Desk that ships with the solution sites. Therefore, the Active attribute is set to false when you create a multi-valued Site Term property, and the property does not appear when you edit a profile instance in the Business Desk.

You can use the Commerce.BusinessDataAdmin object, which ships with Commerce Server 2000, to retrieve a list of Site Terms. (Note: This object is not documented in the online documentation). You can then use the list of Site Terms to implement custom pages that provide multi-valued Site Term functionality. The following sample code demonstrates a possible implementation for these pages.

This code refers to a site where a Site Term group called &quot;Favorites&quot; is added, and a Site Term property called &quot;FavoritePets&quot; is created under this. The Site Term group and Site Term property to display are passed in the call to DisplaySiteTerms. The first page uses check boxes to select the required Site Terms that are passed in the query string to the second page.

NOTE: This is sample code, and the following items should be addressed in a production environment:
 * The Site Name is hard coded and is usually retrieved from the Application object.
 * Error checking is omitted for clarity.

<% ' The site name would normally be retrieved from the Application object. SiteName = &quot;SupplierAD&quot; ' Set this variable to the URL of the page to receive the SiteTerm list selected. strNextPage = &quot;updateprofile.asp&quot;

' Call this sub with Site Term group name and property name to build the list. Sub DisplaySiteTerms(GroupName, PropertyName) ConnStr = GetConnectionString(SiteName) Set SiteTerms = RequestTerms(ConnStr, GroupName, PropertyName) Call DrawSelection(SiteTerms) End Sub

' Get the BizDataStore connection string. Function GetConnectionString(strSiteName) Set SiteCFG = Server.CreateObject(&quot;Commerce.SiteConfigReadOnly&quot;) SiteCFG.Initialize strSiteName GetConnectionString = SiteCFG.Fields(&quot;Biz Data Service&quot;).Value. _       Fields(&quot;s_BizDataStoreConnectionString&quot;).Value End Function

' This function returns a collection of XML nodes representing the requested Site Terms. Function RequestTerms(strConnStr, strGroupName, strPropertyName) ' Create Biz Data Admin Object. Set BDAO = Server.CreateObject(&quot;Commerce.BusinessDataAdmin&quot;) BDAO.Connect strConnStr

' Get the Site Terms Catalog. This is returned as an XML document. Set SiteTermsXML = BDAO.GetProfile(&quot;Site Terms.MSCommerce&quot;)

' Build the XSL Pattern and get the requested site terms. strTermExpression = &quot;//Group[@name='&quot; & strGroupName & &quot;']&quot; strTermExpression = strTermExpression & &quot;/Property[@name='&quot; & strPropertyName & &quot;']&quot; strTermExpression = strTermExpression & &quot;/Attribute&quot; Set RequestTerms = SiteTermsXML.SelectNodes(strTermExpression) End Function

' Present the site terms as a list of check boxes. Each check box has a ' display, which is the display name of the term, and a value, which is the ' name of the term. Modify as appropriate. Note: These should be the only ' elements on the page with the ID of SiteTerm. Sub DrawSelection(xmlTerms) For Each Term in xmlTerms Response.Write &quot;&quot; Response.Write Term.GetAttribute(&quot;displayName&quot;) & &quot;&quot; Next End Sub %>  ' Upon submitting the page, the checked values are passed in a string to the next page. function SubmitValues {   var strParam, termForm, e, currItem; strParam = &quot;&quot;; ' Get a collection of the SiteTerm elements and loop through. termForm = document.all.item(&quot;SiteTerm&quot;); for(e = 0; e < termForm.length; e++) {       currItem = termForm.item(e); ' If the SiteTerm is selected, add it to a semicolon ' separated list. if(currItem.checked == true) {           strParam = strParam + currItem.value + &quot;;&quot; }   }    ' Set the hidden field value to the list minus the trailing semicolon. document.all.item(&quot;theValue&quot;).value = strParam.slice(0,-1); }

Check the site terms you require: <% ' The following call builds and displays the list of Site Terms for selection. Call DisplaySiteTerms(&quot;Favorites&quot;, &quot;FavoritePets&quot;) %> &quot; method=&quot;GET&quot;>   The page that retrieves the form data could then retrieve the selected Site Terms, split them into an array, and update the targeted profile. The following code demonstrates this.

This code refers to a site where a Property group called &quot;Favorites&quot; is added to the UserObject profile, and a multi-valued Property called &quot;FavoritePets&quot; is created under this.

NOTE: This is sample code, and the following items should be addressed in a production environment:
 * The Site Name is again hard coded instead of being retrieved from the Application object.
 * The Profile Service object is created on the page. There is normally one instance of this object that is created in Global.asa and stored in the Application object. This global instance would normally be used on a production page.
 * The specific profile instance to update is hard coded on the page. This is rarely the case in a production page.
 * Error checking is omitted for clarity.

<% Dim strSiteTerms, aTermArray, SiteName, oProfileService, oUser

' The Site Name would normally be retrieved from the Application object. SiteName = &quot;SupplierAD&quot;

' The ProfileService object would normally be retrieved from the Application object. Set oProfileService = GetProfileService(SiteName)

' Get the SiteTerms set into an array. strSiteTerms = Request(&quot;theValue&quot;) aTermArray = Split(strSiteTerms, &quot;;&quot;)

' Get a profile. This would not normally be hard coded. Set oUser = oProfileService.GetProfile(&quot;JoeUser&quot;, &quot;UserObject&quot;)

' Modify and update the multi-valued SiteTerm with the information provided. oUser.Favorites.FavoritePets = aTermArray oUser.Update

Function GetProfileService(strSiteName) Dim oProf, strConn strConn = GetConnectionString(strSiteName) Set oProf = Server.CreateObject(&quot;Commerce.ProfileService&quot;) oProf.Initialize strConn, &quot;Profile Definitions&quot; Set GetProfileService = oProf End Function

' Get the Profile Service connection string. Function GetConnectionString(strSiteName) Set SiteCFG = Server.CreateObject(&quot;Commerce.SiteConfigReadOnly&quot;) SiteCFG.Initialize strSiteName GetConnectionString = SiteCFG.Fields(&quot;Biz Data Service&quot;).Value. _       Fields(&quot;s_BizDataStoreConnectionString&quot;).Value End Function %>

The profile has been updated. NOTE: Commerce Server 2000 stores multi-valued site terms the same way it stores multi-valued strings. Therefore, you can use a multi-valued string if you are managing all site terms through custom code for the profile property in question. This allows the property to be active and editable in Business Desk; however, the Business Desk does not restrict the property values to valid site terms. In this case, the Business Desk edit field displays the multiple values as one string with the various Site Terms separated by semi-colons.

NOTE: Multi-valued strings are stored in the underlying database, separated by semi-colons, and prefixed with the number of entries. For example, using the preceding pages, if you select the dog, fish, and rabbit for favorite pets, a string of &quot;3;dog;fish;rabbit&quot; is stored in the underlying database. The combined length of the selected site terms, plus allowances for the semi-colons and numeric prefix, cannot exceed the length of the underlying database column.

The functionality in the sample pages can be exposed through a custom Business Desk module or on pages on the customer Web site.

Additional query words: cs2k comm2k siteterms

Keywords: kbinfo KB280721

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.