Copied to clipboard

Flag this post as spam?

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


  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 16:00
    RoboDog
    0

    How to set a custom datatype property via api

    Hi can anyone tell me how i set a custom datatype property when creating a new document.

    For example i have created a new document like so : Document newDoc = Document.MakeNew("Text", docType, user, parentNode);

    I am then setting properties of the document like so : newDoc.getProperty("PropertyName").value = "Something";

    however when i try to set a property of a custom type based on dropdownlist the value is not stored i have tried setting it as both a string and an integer.

    Any ideas ?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 16:14
    Thomas Höhler
    0

    it depends on which datatypes are used. Some are storing the values as string some as ids and some as comma separated strings or ids. Take a look into the /data/umbraco.config there you can see how the values get published...

    hth, Thomas

  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 16:45
    RoboDog
    0

    Thanks that sort of set me in the right direction its set as cdata how do i pass this in from the api ? any ideas ?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 16:59
    Thomas Höhler
    0

    have to correct myself: in the database table cmsPropertyData you can see that all these types (checkboxlist or dropdownlist etc) are stored in the column dataNText so it has to be set as strings. the umbraco.config is populated different so there are datatypes where are put into the xml as the text value of the datatype prevalue or as the id.

    But both are set via code as a string value. So if you have an int to set it would be

    document.getProperty("myalias").value = myint.ToString();

    hth, Thomas

  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 17:03
    RoboDog
    0

    have tried this and although it doesnt cause an error the property is never set and always remains unselected. ?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 17:10
    Thomas Höhler
    0

    will test it in my install...

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 17:28
    Thomas Höhler
    0

    Just tested it and this code worked fine for me with a checkbox datatype:

    var d = new umbraco.cms.businesslogic.web.Document(2590);
    d.getProperty("Firma").Value = "29,30";
    d.Publish(new umbraco.BusinessLogic.User(0));
    umbraco.library.UpdateDocumentCache(d.Id);

    hth, Thomas

  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 17:30
    RoboDog
    0

    interesting what is "29,30" ?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 17:33
    Thomas Höhler
    0

    It is the id of the prevalue. Check the values of the datatype in the developer section.

    Thomas

  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 17:44
    RoboDog
    0

    ok so i think i am being numb now why do you have to number i.e 29,30 but my are single i.e 5 and doesn't work tell me if im being dumb here.

  • RoboDog 21 posts 41 karma points
    Feb 03, 2010 @ 18:04
    RoboDog
    0

    ok never mind i worked it out the datatype has to be ntext then it works thanks for your help.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 21:22
    Thomas Höhler
    0

    It's because the checkboxlist allows more than one item to be checked, so this example shows that I have checked two checkboxes. That's all. if you are using a dropdownlist you only can select one item and this will give you only the possibility to store one id.

    ;-)

  • RoboDog 21 posts 41 karma points
    Feb 04, 2010 @ 10:55
    RoboDog
    0

    Ok i do have one problem your solution seems to work how ever if you only try and set one of the checkbox items it doesnt work for me any idea ?

  • RoboDog 21 posts 41 karma points
    Feb 04, 2010 @ 11:01
    RoboDog
    0

    never mind i was being stupid doh

Please Sign in or register to post replies

Write your reply to:

Draft