Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fredrik 89 posts 108 karma points
    Mar 15, 2011 @ 15:21
    Fredrik
    0

    Set value on publish

    On publish I would like to set a value to a numeric textbox on my documenttype Product  to 0 only if it is empty.

    I did this, but it does no good.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using umbraco;
    namespace AutoSetPrice
    {
        public class AutoSetPriceHandler
        {
            public AutoSetPriceHandler()
            {
                Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
            }
            void Document_BeforePublish(Document sender, PublishEventArgs e)
            {
                if (sender.ContentType.Alias == "Product")
                {
                    if (sender.getProperty("price").Value == null || sender.getProperty("price").Value.ToString() == "")
                    {
                        sender.getProperty("price").Value = 0;
                        umbraco.library.UpdateDocumentCache(sender.Id);
                    }
                }
            }
        }
    }
  • Harald Ulriksen 207 posts 249 karma points
    Mar 15, 2011 @ 15:29
    Harald Ulriksen
    0

    You need to inherit from the abstract class umbraco.BusinessLogic.ApplicationBase in businesslogic.dll

    h.

Please Sign in or register to post replies

Write your reply to:

Draft