Welcome to MSDN Blogs Sign in | Join | Help

Cristiano WebLog

Microsoft Infrastructure & Development Tips and Tricks
Programming Display Windows - Static Version [Part II]

If you followed the last post you now have a brand new DisplayTemplate on the marketing system with three properties: ProductImage, ProductTitle and ProductPrice.

Before creating new advertisements and associate the new DisplayTemplate we will need an expression. This expression will be used to filter only advertisements for a determined display window.

To do that, we need two steps:

  1. Create a new targeting context attribute called BillBoard using the Commerce Server Manager.
  2. Create a new global expression to be used on the Target Expressions of the advertisements that we will create on the next post. :)

Step 1

  • Open the Commerce Server Manager and navigate to Commerce Server Manager/Global Resources/Profiles(<Your Server>_StarterSite_Profiles)/Profile Catalog/Profile Definitions/Targeting Context
  • On the right side of the window, click Add.
  • Select Add New Property and click OK.

image 

  • Fill the boxes Name and DisplayName with BillBoard.
  • Very important!!! Click Apply and on the small diskette icon on the top of the Commerce Server Manager.
  • Your profile definition will be like the following picture:

image

Step 2

Great. Now we have a new TargetingContext property. It's time to create a new global expression. This expression will be associated to the advertisement and will be used during the  content selection to filter only advertisements fitting to our display window.

The following code can be used on a Console Application to create the appropriate global expression:

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;
using System.Xml;

namespace CreateGlobalExpression
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set the URL to the Web service.
            string marketingWebServiceUrl = @"
http://localhost/MarketingWebService/MarketingWebService.asmx";
            // Create an instance of the Marketing System agent.
            MarketingServiceAgent ma = new MarketingServiceAgent(marketingWebServiceUrl);
            MarketingContext marketingSystem = MarketingContext.Create(ma);

            //Creating the global expression
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement clause = xmlDoc.CreateElement("CLAUSE");
            clause.SetAttribute("OPER", "equal");

            XmlElement property = xmlDoc.CreateElement("PROPERTY");
            property.SetAttribute("ID", "TargetingContext.BillBoard");
            property.SetAttribute("TYPE", "STRING");

            XmlElement immedval = xmlDoc.CreateElement("IMMED-VAL");
            immedval.SetAttribute("TYPE", "STRING");

            XmlElement value = xmlDoc.CreateElement("VALUE");
            value.InnerText = "MainDisplayWindow";

            immedval.AppendChild(value);
            clause.AppendChild(property);
            clause.AppendChild(immedval);

            // Create a new expression.
            Expression ex = marketingSystem.Expressions.NewExpression(false);
            ex.Description = "BillBoard Select Expression";
            ex.Body = clause;
            ex.Name = "BillBoard";
            ex.Category = "TargetCondition";
            ex.Save(true);

        }
    }
}

The attachment has a zip file with a console application to create the expression.

See you later, Cris.

This posting is provided "AS IS" with no warranties, and confers no rights.

Posted: Tuesday, July 03, 2007 8:09 PM by crisag

Attachment(s): CreateGlobalExpression.zip

Comments

Noticias externas said:

If you followed the last post you now have a brand new DisplayTemplate on the marketing system with three

# July 3, 2007 6:22 PM

davidme said:

Hi Cris,

Did you consider using Page Groups for the filtering instead of expressions?  Page Groups are a more efficient way to filter advertisements down for display in a given location or set of locations on your site.  They are considerably more lightweight than targeting expressions.

Hope that helps.  Great post series - keep it up!

-David

# July 10, 2007 12:23 PM
Anonymous comments are disabled
Page view tracker