Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Multi-Valued Site Term Properties in Commerce 2000 Profiles


View products that this article applies to.

This article was previously published under Q280721

↑ Back to the top


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.

↑ Back to the top


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 "Favorites" is added, and a Site Term property called "FavoritePets" 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.
<html>
<head>
</head>
<%
' The site name would normally be retrieved from the Application object.
SiteName = "SupplierAD"
' Set this variable to the URL of the page to receive the SiteTerm list selected.
strNextPage = "updateprofile.asp"

' 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("Commerce.SiteConfigReadOnly")
	SiteCFG.Initialize strSiteName
	GetConnectionString = SiteCFG.Fields("Biz Data Service").Value. _
		Fields("s_BizDataStoreConnectionString").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("Commerce.BusinessDataAdmin")
	BDAO.Connect strConnStr

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

	' Build the XSL Pattern and get the requested site terms.
	strTermExpression = "//Group[@name='" & strGroupName & "']"
	strTermExpression = strTermExpression & "/Property[@name='" & strPropertyName & "']"
	strTermExpression = strTermExpression & "/Attribute"
	
	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 "<INPUT TYPE=CHECKBOX ID='SiteTerm'" 
		Response.Write "VALUE='" & Term.GetAttribute("name") & "'>"
		Response.Write Term.GetAttribute("displayName") & "</BR>"
	Next
End Sub
%>
<script language="JavaScript">
' Upon submitting the page, the checked values are passed in a string to the next page.
function SubmitValues()
{
	var strParam, termForm, e, currItem;
	strParam = "";
	
	' Get a collection of the SiteTerm elements and loop through.
	termForm = document.all.item("SiteTerm");
	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 + ";"
		}
	}
	
	' Set the hidden field value to the list minus the trailing semicolon.
	document.all.item("theValue").value = strParam.slice(0,-1);
}
</script>

<body>
Check the site terms you require:<BR/>
<% 
' The following call builds and displays the list of Site Terms for selection.
Call DisplaySiteTerms("Favorites", "FavoritePets")
%>
<form id=sendData action="<%= strNextPage %>" method="GET">
	<INPUT TYPE=HIDDEN NAME="theValue" VALUE="">
	<INPUT type=SUBMIT VALUE="Submit" onClick="JavaScript:SubmitValues();">
</form>
</body>
</html>
				
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 "Favorites" is added to the UserObject profile, and a multi-valued Property called "FavoritePets" 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.
<html>
<body>
<%
Dim strSiteTerms, aTermArray, SiteName, oProfileService, oUser

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

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

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

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

' 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("Commerce.ProfileService")
	oProf.Initialize strConn, "Profile Definitions"
	Set GetProfileService = oProf
End Function

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

The profile has been updated.
</body>
</html>
				
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 "3;dog;fish;rabbit" 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.

↑ Back to the top


Keywords: KB280721, kbinfo

↑ Back to the top

Article Info
Article ID : 280721
Revision : 2
Created on : 11/4/2002
Published on : 11/4/2002
Exists online : False
Views : 279