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.
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...
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
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);
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.
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 ?
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
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 ?
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
hth, Thomas
have tried this and although it doesnt cause an error the property is never set and always remains unselected. ?
will test it in my install...
Just tested it and this code worked fine for me with a checkbox datatype:
hth, Thomas
interesting what is "29,30" ?
It is the id of the prevalue. Check the values of the datatype in the developer section.
Thomas
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.
ok never mind i worked it out the datatype has to be ntext then it works thanks for your help.
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.
;-)
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 ?
never mind i was being stupid doh
is working on a reply...