Monday 15 February 2016

Commerce Server Error : The requested profile could not be retrieved

Leave a Comment
I've been working with Sitecore Commerce 8 powered by Commerce Server now for a while and trying to configure the demo store which is based upon Reference Storefront solution provided by Sitecore commerce product team.  I’ve successfully managed to get the demo store running after following configuration steps however I’d faced few issues while setting it up. In my upcoming blog posts I’ll be sharing my learning on some troubleshooting I went through.

I was trying to create a user account in demo storefront website. I got below error once I clicked on create user button after entering relevant details in create an account form.   
Register: The requested profile could not be retrieved because the key name provided does not exist or is not an indexed property. The profile type is 'UserObject'. The key name provided is ‘GeneralInfo.ExternallD’.
In order to resolve above issue, I did following steps:
  1. Verify that profile schema is correct. If profile schema is incorrect then import profile schema again.
  2. After importing schema, modify Sitecore Commerce 8.0 powered by Commerce Server Profile Schema for Sitecore Integration as described here.
  3. I have found that profile database schema was not correct and u_external_id column was missing in UserObject table of profile database.
  4. Make the following changes in UserObject table of profile database:
    Add column: u_external_id NVARCHAR(256) NOT NULL
    IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'userobject' AND COLUMN_NAME = 'u_external_id')
    BEGIN
     ALTER TABLE dbo.UserObject ADD u_external_id nvarchar(256) NOT NULL
    END
    GO
    
    Create Index on: u_external_id, UNIQUE NONCLUSTERED INDEX and ASC
    IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[UserObject]') AND name = N'IX_UserObject_ExternalId')
     DROP INDEX [IX_UserObject_ExternalId] ON [dbo].[UserObject]
    GO
    
    IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[UserObject]') AND name = N'IX_UserObject_ExternalId')
    CREATE UNIQUE NONCLUSTERED INDEX [IX_UserObject_ExternalId] ON [dbo].[UserObject]
    (
     [u_external_id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    
  5. Update Sitecore Commerce 8.0 powered by Commerce Server Profile Schema. Add a new GeneralInfo.ExternalId profile property that maps to the external id column, it must be required and unique. This blog explains how to add new property to user object in commerce server profile system.
  6. Refresh the cache and reload the register account page. You should no longer get the above error message and should be able to create new user account in demo storefront website.
Comments and suggestions are most welcome. Happy coding!  
Read More...

Commerce Server : How to add a Property to a Profile Definition

Leave a Comment
In this blog post I am going to explain how to add a new Property to a Profile Definition in Sitecore Commerce Server. For example, I’ll show how to add a new property ExternalId to User object into Profile Definition of Sitecore Commerce Server.

Add new column in SQL Server table
  1. Make the following changes in UserObject table of profile database in SQL server:
    Add column: u_external_id NVARCHAR(256) NOT NULL
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'userobject' AND COLUMN_NAME = 'u_external_id')
BEGIN
 ALTER TABLE dbo.UserObject ADD u_external_id nvarchar(256) NOT NULL
END
GO
Create new Data member in Commerce Server Manager
  1. Open Commerce Server Manager. Expand Commerce Server Manager -> Global Resources -> Profiles -> Profile Catalog -> Data Sources -> ProfileService_SQLSource -> Data Objects. Right click the data object you want to add a data member to, and then click New Data Member. I am going to add new data member to User object.
  2. In the New Data Member dialog box, complete below fields:
    Field NameDetails
    Member NameSelect an available data member name from the list. Data members which have already been added to a data object will be unavailable for selection and appear dimmed. The member name must match the name of the column to which the data member maps in SQL server table. The member name can contain a maximum of 127 alphanumeric characters and the underscore (_) symbol. The member name cannot contain spaces.
    Display NameType a display name that contains a maximum of 127 Unicode characters.
    DescriptionType a description for the data member. The description can contain a maximum of 127 Unicode characters.
    TypeSelect the appropriate data type for the data member. The data type must be the same as the property that you will map with the data member.
    Multi-valuedSelect this option to enable the collection of multiple values that are associated with the data member.
    RequiredSpecifies that this property is required on your Web site. However, the Profiles Schema Manager does not enforce this attribute.
    IndexedSelect this option if you want the data indexed on this data member.
    Primary keySelect this option to designate this data member as the primary key. You must select one data member in each data object to be the primary key.
  3. Click Add. The data member appears in the data member list in the New Data Member dialog box.
  4. Click Finished.
Map the data member to a property in profile object.
  1. Open Commerce Server Manager. Expand Commerce Server Manager -> Global Resources -> Profiles -> Profile Catalog -> Profile Definitions. Left click the profile definition object where you want to add a new property. I’ve selected User object profile definition.
  2. Select appropriate information group and then click on Add to add new property.
  3. The property will be appeared in general information group with a new name called New Property 1.
  4. Select New Property 1. You can see a property editor in the right hand section.
  5. Fill the fields in Attributes section. 
  6. Fill the fields in Advanced attributes section. Click on Map to data to map the newly created data member to new property.
  7. Fill the fields in Custom attributes section as per requirement.
  8. Click on apply to save the changes of new property. Now the new property is added to User object.
Comments and suggestions are most welcome. Happy coding!
Read More...