I wasn't able to find a way to get the prevalues for the datatype through the Umbraco API without having to hard code the DataType ID.
However, this is the SQL Query that I came up with to get the data directly from the database.
select p.id, p.value from cmsDataTypePreValues p inner join umbracoNode n on p.datatypeNodeId = n.id inner join cmsDataType t on n.id = t.nodeId where n.text = 'Name Of Datatype'
You would replace "Name Of Datatype" with the name you used when you created the datatype.
Hopefully this could be added to the umbraco library sometime.
that certainly looks more concise... :-) not sure why I went around the houses..
seem to remember some issue where I was getting the name of the property editor that was chosen for the datataype rather than the actual datatype name, but memory fails me now..
var dataTypeService = ApplicationContext.Services.DataTypeService; var allTypes = dataTypeService.GetAllDataTypeDefinitions(); var typeId = allTypes.First(x => "My Data Type".InvariantEquals(x.Name)).Id; var values = dataTypeService.GetPreValuesByDataTypeId(typeId);
var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
var allTypes = dataTypeService.GetAllDataTypeDefinitions();
var typeId = allTypes.First(x => "My Data Type".InvariantEquals(x.Name)).Id;
var values = dataTypeService.GetPreValuesByDataTypeId(typeId);
Is there a way to get this same information in Angular? The dataTypeResource in 7.2.1 has getPreValues, but you have to pass it the dataType ID. It would be nice if there was a "getByAlias" function here, but there isn't.
I can create my own API and resource, but would rather not.
Getting Datatype ID
Hello,
Using the API, I'm trying to get the prevalues of a DataType that I created.
I'm using this method:
XPathNodeIterator
xml = umbraco.library.GetPreValues(1067);
How can I get the ID of the datatype so that I do not have to hard code the ID number?
Thanks,
Daniel
I wasn't able to find a way to get the prevalues for the datatype through the Umbraco API without having to hard code the DataType ID.
However, this is the SQL Query that I came up with to get the data directly from the database.
select p.id, p.value
from cmsDataTypePreValues p
inner join umbracoNode n on p.datatypeNodeId = n.id
inner join cmsDataType t on n.id = t.nodeId
where n.text = 'Name Of Datatype'
You would replace "Name Of Datatype" with the name you used when you created the datatype.
Hopefully this could be added to the umbraco library sometime.
Thanks,
Daniel Burge
Burada, Inc.
http://www.buradainc.com
something like this...
DataTypeDefinition.GetAll().First(dtDef => dtDef.DataType.DataTypeName.ToString() == "DATATYPENAME").DataType.DataTypeDefinitionId
Following Mike answer, I achieved the same using different properties:
var dataTypeId = DataTypeDefinition.GetAll().First(dtDef => dtDef.Text == "DATA TYPE NAME").Id;
that certainly looks more concise... :-) not sure why I went around the houses..
seem to remember some issue where I was getting the name of the property editor that was chosen for the datataype rather than the actual datatype name, but memory fails me now..
Im interested in using the above code for getting a datatypeId from its name. However i am getting this error for GetAll():
Compiler Error Message: CS0117: 'Umbraco.Core.Models.DataTypeDefinition' does not contain a definition for 'GetAll'
Has GetAll been removed since the solution was posted? (Running Umbraco v6.1.6 (Assembly version: 1.0.5021.24867))
Thanks in advance.
This is how I got it working in Umbraco 6.1.6:
This is how I got it working in Umbraco 7:
Is there a way to get this same information in Angular? The dataTypeResource in 7.2.1 has getPreValues, but you have to pass it the dataType ID. It would be nice if there was a "getByAlias" function here, but there isn't.
I can create my own API and resource, but would rather not.
is working on a reply...