Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I posted in this forum a little while ago about the options available to developers to work with the Umbraco back-end programmatically. Since then I've been cracking on with using the API and have successfully created a document type using this snippet:
umbraco.BusinessLogic.User user = new umbraco.BusinessLogic.User("admin");
DocumentType dt = DocumentType.MakeNew(user, "Test Template");dt.Description = "Test template description";dt.Alias = "testTemplate";dt.Save();
I then went on to flesh out my document type with a new property (as you would in the web interface by going to "Generic Properties" and creating a new property manually. This was less straightforward as I couldn't find any good examples, and the API documentation for the PropertyType class usefully says "Summary description for propertytype"! But I've managed to piece together something that seems to work in order to create a boolean property on my new document type:
dt.AddPropertyType(new umbraco.cms.businesslogic.datatype.DataTypeDefinition(-49), "bOptIn", "Opt In");dt.Save();
The thing I'm wondering now is how would I add this property to a custom tab. For example, I know also that I can create a custom tab on the document type using:
dt.AddVirtualTab("My custom tab");dt.Save();
But it's specifying that the new property I'm creating is to belong to this new tab that's causing me bother. Can anyone fill me in on how to do this?
I think you should be able to do the following:
int tabId = dt.AddVirtualTab("My Custom Tab");dt.AddPropertyType(DataTypeDefinition(-49), "bOptIn", "Opt In");dt.SetTabOnPropertyType(dt.getPropertyType("bOptIn"), tabId);dt.Save();
That's done it, thanks Matt.
How did you guys manage to get it working? I keep getting:
I'm using Umbraco 4.7.1.
@donatas the method no longer returns null
In the older version of Umbraco the method's return type was public void AddPropertyType whereas the new one public PropertyType AddPropertyType
public void AddPropertyType
public PropertyType AddPropertyType
So the final code(assuming correct assemblies are referenced):
var dt =DocumentType.GetByAlias("TestDocType");var pType = dt.AddPropertyType(newDataTypeDefinition(-49),"testprop","test prop");
the above was shamelessly copied from stackoverflow
Thanks Rob, in the end I got it working. BTW that's my post on stackoverflow :)
In case anyone stumbles on this question and is using Umbraco 8, I have written how to create custom properties for members here https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/78210-add-custom-property-to-membership-member#comment-335629
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted