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 24, 2011 @ 17:14
    Fredrik
    0

    Document does not change on save and publish

    Hi,

    I want to be able to change values in my created documents programmatically. At the moment I use this code, with no significant amount of success ;) What seems to be the problem? No errors, just no effect on the backend!

    using umbraco.presentation.nodeFactory;
    using umbraco.cms.businesslogic.web;
    using umbraco.BusinessLogic;

    namespace MySite
    {
        public partial class ChangeInfo : System.Web.UI.UserControl
     
    protected void UpdateDocument()
            {
                DocumentType dt = DocumentType.GetByAlias("Customer");
                User author = User.GetUser(0);
                Document doc = new Document(GetCurrentUser().Id);

               
                doc.getProperty("email").Value = EmailTxtBox.Text;

                doc.getProperty("companyName").Value = CompanyTxtBox.Text;

                doc.getProperty("orgNr").Value = OrgNrTxtBox.Text;

                doc.getProperty("companyPhone").Value = CompanyPhoneTxtBox.Text;

                doc.getProperty("industry").Value = IndustryDropDown.SelectedItem.Value;

                if (GreenBillingCheckBox.Checked == true)
                {
                    doc.getProperty("green_billing").Value = true;
                }
                else
                {
                    doc.getProperty("green_billing").Value = false;
                }

                //Leveransadress
                doc.getProperty("delivery_streetAddress").Value = ShippingStreetTxtBox.Text;
                doc.getProperty("delivery_postalCode").Value = ShippingPostalCodeTxtBox.Text;
                doc.getProperty("delivery_city").Value = ShippingCityTxtBox.Text;
                doc.getProperty("delivery_country").Value = ShippingCountryTxtBox.Text;

                //Faktureringsadress
                doc.getProperty("billing_streetAddress").Value = BillingStreetTxtBox.Text;
                doc.getProperty("billing_postalCode").Value = BillingPostalCodeTxtBox.Text;
                doc.getProperty("billing_city").Value = BillingCityTxtBox.Text;
                doc.getProperty("billing_country").Value = BillingCountryTxtBox.Text;

                //Kontaktperson
                doc.getProperty("full_name").Value = ContactFullNameTxtBox.Text;
                doc.getProperty("contact_email").Value = ContactEmailTxtBox.Text;
                doc.getProperty("contact_phoneNr").Value = ContactPhoneTxtBox.Text;


                doc.Save();
                doc.Publish(author);


                umbraco.library.UpdateDocumentCache(doc.Id);

            }
  • Rich Green 2246 posts 4008 karma points
    Mar 24, 2011 @ 17:33
    Rich Green
    1

    You're supposed to be referencing the node ID in this line, not the user.

    Document doc = new Document(GetCurrentUser().Id);

    You need something like (replace 1029 with the node if you need to edit)

    Document doc = new Document(1029);

    Also, you don't need doc.Save (I believe) and this line doesn't do anything in your code

     DocumentType dt = DocumentType.GetByAlias("Customer");

    http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties

    Rich

     

  • Fredrik 89 posts 108 karma points
    Mar 25, 2011 @ 08:22
    Fredrik
    0

     

    This is my method for retrieving the node which contains the ID used in Document(GetCurrentUser().Id).

     It is not a user ID. It does retrieve the correct Id.

            protected Node GetCurrentUser()
            {
                Node node = new umbraco.presentation.nodeFactory.Node(1785);
                foreach (Node child in node.Children)
                {
                    foreach (Node child2 in child.Children)
                    {
                        if (child2.GetProperty("email").Value.ToString().ToUpper().Trim() == Session["loggedInAs"].ToString().ToUpper().Trim())
                        {
                            return child2;
                        }

                    }
                }
                return node;
            }
  • Fredrik 89 posts 108 karma points
    Mar 25, 2011 @ 08:36
    Fredrik
    0

    I found that it does update the properties if I set the value in the code like

    doc.getProperty("companyName").Value = "Company A";

     

    Although from a textbox it does not work ....why!?

    doc.getProperty("companyName").Value = CompanyTxtBox.Text;


     

  • Rich Green 2246 posts 4008 karma points
    Mar 25, 2011 @ 08:40
    Rich Green
    0

    Did you try to step through / debug your code?

    Rich

  • Fredrik 89 posts 108 karma points
    Mar 25, 2011 @ 08:48
    Fredrik
    0

    I don't know how to attatch debugger to my project since I copy my files from the projetct folder to my umbraco installation folder.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies