Jaa


How to Change the Campaign Item Display Template

You can use the Marketing APIs to create and change campaign item display templates.

To create the campaign item display template

  1. Create a MarketingServiceAgent object.

  2. Create a MarketingContext object.

  3. Create a DisplayTemplate object.

  4. Add the properties.

  5. Save the template by using the Save method on the DisplayTemplate object.

To change the campaign item display template

  1. Get the DisplayTemplate object. To do this, use the GetDisplayTemplate method of the DisplayTemplates property of the MarketingContext object.

  2. Update the properties.

  3. Save the template by using the Save method on the DisplayTemplate. object.

Example

The following sample demonstrates how to create a new campaign item, update an existing template, and display the template.

using System;
using Microsoft.CommerceServer.Marketing;

namespace ConsoleApplication1
{
    // This code requires you to add the following references:
    // Microsoft.CommerceServer.CrossTierTypes
    // Microsoft.CommerceServer.Marketing.CrossTierTypes

    // Make sure that your user account has sufficient Marketing permissions to perform
    // these operations.

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Set the url to the Web service.
                string campaignServiceUrl = @"https://localhost/MarketingWebService/MarketingWebService.asmx";
                // Create an instance of the Marketing System agent
                MarketingServiceAgent ma = new MarketingServiceAgent(campaignServiceUrl);
                MarketingContext marketingSystem = MarketingContext.Create(ma);
                
                // Create a new template.
                DisplayTemplate template = marketingSystem.DisplayTemplates.NewDisplayTemplate();
                template.Name = "Your template name1";
                string dpName1 = "Your template property name";
                template.Properties.Add(new DisplayProperty(dpName1));
                template.Save();

                // Success!
                Console.WriteLine("Successfully created template: {0}", template.Name);
                Console.WriteLine("It has the following properties:");
                foreach (DisplayProperty displayprop in template.Properties)
                {
                    Console.WriteLine(displayprop.Name);
                }

                // Update an existing template.
                int id = template.Id;
                template = marketingSystem.DisplayTemplates.GetDisplayTemplate(id);
                string name = "Your template name2";
                template.Name = name;

                string text = "Your template text.";
                template.Text = text;

                string dpName2 = "Your template second property name";
                DisplayProperty displayProp = new DisplayProperty(dpName2);

                template.Properties.Add(displayProp);
                template.Save();

                // Success!
                Console.WriteLine("\r\nSuccessfully updated template: {0}", template.Name);
                Console.WriteLine("It has the following properties:");
                foreach (DisplayProperty displayprop in template.Properties)
                {
                    Console.WriteLine(displayprop.Name);
                }
               
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
                }
                Console.ReadLine();
            }
        }
    }
}

See Also

Other Resources

Campaign Concepts and Tasks