Code to Retrieve and Set Multi-Valued Attributes

In this example, a previous page has posted a value titled "theValue" which contains multiple values in a string separated by semicolons: "valueone;valuetwo;valuethree". This is split into an array using the VBScript Array() function and then used to update the users profile.

The following points hold for this example:

  • The Site Name is 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>

Copyright © 2005 Microsoft Corporation.
All rights reserved.