Creating references to your objects in Management Center

I was looking into creating a reference editor to show an reference between my object to an SKU and I think it wasn’t obvious how to get this relationship to work.

First of I wanted to use the reference editor to show my relationship. I defined it using the code below. I didn’t want the ability to create new objects with the reference editor, and I wanted it to be required input.

<ReferenceEditor allowCreate="false" extendedHelpText="${HelpText}" 
    headerText="${Header}"
    name="catEntryRefEditor" promptText="${Prompt}"
    referenceObjectTypes="RefCatalogEntry"
    required="true" />

To enable the reference I created a base reference object definition using the code below. Most of the variables are self explanatory but that I use the objectGroups to define the objectPath for my CreateService and UpdateService wasn’t obvious.

<ReferenceObjectDefinition definitionName="BaseCatEntryType" 
    displayNameProperty="partnumber" isBaseDefinition="true" 
    initializeObjectStoreId="true" allowDuplicates="false" 
    derivedId="true" idProperty="catentryId" 
    objectGroups="ObjectReference" />

Next I created an instance inside my object for the reference types I wanted to relate to.

<ReferenceObjectDefinition baseDefinitionName="BaseCatEntryType" 
    objectType="RefCatalogEntry" 
    referencedTypes="ProductSKU,InheritedProductSKU,CatalogGroupSKU,InheritedCatalogGroupSKU"/>

This steps should enable you to select an SKU and reference it to your object. And if you save the object with a ServiceParam with objectPath ObjectReference and propertyName catentryId you should get the value of the selected SKU into your command.

Secondly we want to load the value back into the reference editor. This was one of the things taking the longest time for me to figure out. After days of debugging I found that you don’t use the GetReferencesService but the GetChildrenService using your Reference object type as the objectType param.

<GetChildrenService objectTypes="RefCatalogEntry" url="/cmc/GetCatEntryReferences">
    <ServiceParam name="objectId" propertyName="objectId"/>
</GetChildrenService>

The JSP returning the value have to look something like below (I had to use dashes in objects and object for some reason to save this code). The first object type below is the object type of the reference object. The inner object type is the actual object type of your referenced object, in my case CatalogGroupSKU. I had to give the reference object both catentryId and partnumber to show the reference value correctly in the editor and save the value directly. And then the inner object needs both catentryId and partnumber to display the object when it is loaded. If you don’t supply both values to the inner object you will either not show an catalog entry you click on the reference or the code field will not be filled when you arrive at the property view.

<obj-ects>
    <obj-ect objectType="RefCatalogEntry">
        <catentryId><wcf:cdata data="${catentryId}"/></catentryId>
        <partnumber><wcf:cdata data="${partnumber}"/></partnumber>
        <obj-ect objectType="${objectTypeRef}">
            <catentryId><wcf:cdata data="${catentryId}"/></catentryId>
            <partnumber><wcf:cdata data="${partnumber}"/></partnumber>
        </obj-ect>
    </obj-ect>
</obj-ects>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s