Code snippet to add a Create link

To add a Create link either directly in a store page or in a store preview pop-up window, you must use a specific code snippet. The code snippet constructs a Management Center CreateBusinessObject URL for a specific type of business object, such as an e-Marketing Spot or web activity. You can also specify values for any fields that you want to prefill in the properties view for the new business object.

Parameters for a Create link

The Create link must include a set of parameters that provide Management Center with information about the type of business object to create. You must provide values for the variables that are shown in italic text:
<c:url var = "clickToCreateURL" value = "/cmc/CreateBusinessObject" context = "/">
    <c:param name = "toolId" value = "toolId"/>
    <c:param name = "storeId" value = "storeId"/>
    <c:param name = "languageId" value = "langId"/>
    <c:param name = "storeSelection" value = "storeSelection"/>
    <c:param name = "objectType" value = "objectType"/>
    <c:param name = "newObjectOption.keyPropertyName" value = "prefilledValue"/>
    ....
    <c:param name = "newObjectOption.keyPropertyName" value = "prefilledValue"/>
</c:url>
<a href="javascript:void(0)" onclick="parent.callManagementCenter('<wcf:out escapeFormat="js" value="${clickToCreateURL}"/>');">Create</a>

The variables are as follows:

toolId
The ID of the Management Center tool in which the business object is managed. The click-to-edit function uses this ID to open the correct tool when the business user clicks the link. For example, catalogManagement is the tool ID for the Catalogs tool, and marketingManagement is the tool ID for the Marketing tool.

You can look up the tool ID in the ApplicationMenuItems.def file, which defines all the menu items in Management Center:

WCDE_installdir/workspace/LOBTools/WebContent/config/commerce/shell/ApplicationMenuItems.def

For example, in the ApplicationMenuItems.def file, the ID for the Catalogs tool is specified as the id parameter value in the line of code that is shown in bold text:

<ApplicationMenuItem
    actionName = "openBusinessObjectEditor"
    activeIconSrc = "catalogActiveTabIcon"
    displayName = "${shellResourceBundle.catalogManagementDisplayName}"
    id = "catalogManagement"
    inactiveIconSrc = "catalogInactiveTabIcon"
    toolDefinitionName = "catCatalogManagement"
    usage = "IBM_ViewCatalogTool"/>
storeId
The ID of the store that is being previewed. The click-to-edit function uses this ID to determine which store to select in Management Center. You can use the store ID variable ${storeId} so that the current store ID is retrieved and passed in the click-to-edit URL.

WebSphere Commerce DeveloperWebSphere Commerce EnterpriseFor an extended site, the storeSelection value is also used to determine which store to select in Management Center.

langId
The language ID for the store that is being previewed. You can use the language ID variable ${langId} so that the current language ID is retrieved and passed in the click-to-edit URL.
WebSphere Commerce DeveloperWebSphere Commerce EnterprisestoreSelection
WebSphere Commerce DeveloperWebSphere Commerce EnterpriseFor an extended site, the store preference value for the link. This parameter defines the store type to select in Management Center when the business user clicks the link. Valid values are as follows:
prompt
Display a prompt that lets the business user select either the asset store or extended site store. This is the default value. If your business users use both the extended site store and the asset store to manage the business objects that relate to this link, use this value.
assetStore
Open the asset store (either the storefront asset store or the catalog asset store, whichever applies to the business object that is being edited). If your business users manage all business objects that relate to this link in the asset stores, use this value.
eSite
Open the extended site store. If your business users manage all business objects that relate to this link in the extended site store, use this value.

If you do not have an extended site, you can ignore this parameter.

An IT developer can change the store preference value at any time.

objectType
The objectType value is required by the Management Center framework to look up the object definition for the object. The framework then creates an instance of the object. For a business object, the objectType value is defined in the object definition file. For example, the object type for a web activity is WebActivity, and the object type for a search rule is SearchActivity.

You can find object definition files for business objects that are shipped with WebSphere Commerce at the following path:

WCDE_installdir/workspace/LOBTools/WebContent/config/commerce/component/objectDefinitions/

For example, in the EMarketingSpotPrimaryObjectDefinition.def file, the objectType parameter value is defined in the last line of code in this snippet:

<PrimaryObjectDefinition
    baseDefinitionName = "mktBaseEMarketingSpotPrimaryObjectDefinition"
    creatable = "true"
    definitionName = "EMarketingSpot"
    objectType = "EMarketingSpot">
    

You can prefill certain field values in the Management Center properties view that opens when the business user clicks the Create link. To do so, specify the following additional values for the newObjectOption parameter:

keyPropertyName
The name of the property that you want to prefill. For example, for a Create link for an e-Marketing Spot, you might want to prefill the Name field in the e-Marketing Spot properties view. If so, you can define the keyPropertyName as marketingSpotName. You can use any name, but you must reference the exact name when you create the JSP to define the prefilled values later in this task flow. See Initializing a new business object for a “Create” link.
prefilledValue
The value of the property that you want to prefill. For example, to prefill the Name field in the e-Marketing Spot properties view, the value is the variable ${emsName}.

Example of the code snippet for a Create link

The following code snippet creates a Create link for an e-Marketing Spot in the Aurora starter store. This code is copied from the ESpotInfoPopupDisplay.jspf file, which is the E-Marketing Spot Information page:
1 <c:if test="${!espotFound}"> 
2   <c:url var="clickToCreateURL" value="/cmc/CreateBusinessObject" context="/">
		  <c:param name="toolId" value="marketingManagement"/>
		  <c:param name="storeId" value="${storeId}"/>
		  <c:param name="languageId" value="${langId}"/>
		  <c:param name="storeSelection" value="prompt"/>
		  <c:param name="objectType" value="EMarketingSpot"/>
		  <c:param name="newObjectOption.marketingSpotName" value="${emsName}"/>
    </c:url>
3    <a id='click2create_EMarketingSpot_<c:out value="${espotName}"/>' 
          title='<fmt:message key="Click2Create_espot" bundle="${previewText}"/>' class="click2create_button" href="javascript:void(0)" 
          onclick="window.parent.callManagementCenter('<wcf:out escapeFormat="js" value="${clickToCreateURL}"/>');">
          <fmt:message key="Click2Edit_Create" bundle="${previewText}"/>
    </a>
  </c:if>
Notes on the example code (refer to the numbered callouts in the snippet):
  • 1 This line of code ensures that the Create link displays only if the e-Marketing Spot does not yet exist in Management Center. The ESpotInfoPopupDisplay.jspf file gets data from the marketing engine to determine whether the e-Marketing Spot exists. The data is returned to the ${!espotFound} variable.
  • 2 This <c:url element defines a variable that is the click-to-create URL.
  • 3 The <a element creates the Create link and calls the callManagementCenter JavaScript function, which submits the URL to the Management Center web application.
    Note: To function properly, a Create link requires only the following portion of the code within the <a element:
    <a href="javascript:void(0)" 
       onclick="parent.callManagementCenter('<wcf:out escapeFormat="js" 
       value="${clickToCreateURL}"/>');">Create</a>
    In the example snippet, the additional code within the <a element is for internal IBM purposes, such as automation, and is not required.