Copied to clipboard

Flag this post as spam?

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


  • Daniel Burge 11 posts 31 karma points
    Jun 24, 2010 @ 17:27
    Daniel Burge
    0

    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

  • Daniel Burge 11 posts 31 karma points
    Jul 23, 2010 @ 00:31
    Daniel Burge
    0

    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

  • Mike Chambers 636 posts 1253 karma points c-trib
    Sep 16, 2011 @ 14:14
    Mike Chambers
    0

    something like this...

     

    DataTypeDefinition.GetAll().First(dtDef => dtDef.DataType.DataTypeName.ToString() == "DATATYPENAME").DataType.DataTypeDefinitionId

  • Francisco 21 posts 72 karma points
    Mar 19, 2013 @ 22:40
    Francisco
    0

    Following Mike answer, I achieved the same using different properties:

     

    var dataTypeId = DataTypeDefinition.GetAll().First(dtDef => dtDef.Text == "DATA TYPE NAME").Id;

     

  • Mike Chambers 636 posts 1253 karma points c-trib
    Mar 20, 2013 @ 18:31
    Mike Chambers
    0

    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..  

  • Magnus Söderlund 19 posts 79 karma points
    Nov 20, 2013 @ 10:50
    Magnus Söderlund
    0

    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.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 09, 2013 @ 17:54
    Nicholas Westby
    0

    This is how I got it working in Umbraco 6.1.6:

    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);
  • Gijs 38 posts 133 karma points
    Sep 19, 2014 @ 16:56
    Gijs
    6

    This is how I got it working in Umbraco 7:

    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);

     

  • Jon Herrell 13 posts 67 karma points
    Jan 26, 2015 @ 18:44
    Jon Herrell
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft