[SOLVED] Get UDI for block list row elements
# help-with-umbraco
j
Hi! When [Creating Blocklist programmatically](https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor#creating-blocklist-programmatically) my understanding is that I need to have the ContentUdi and SettingsUdi for each blocklist row I'm planning on using. How do I find the UDI values for each row - both Content and Settings? Umbraco 10.4.2 End goal is that I've got to slice up a bunch of Markdown documents into different rows to import into the database via ContentService. TIA! Sample from the docs:
Copy code
{
   "layout":{
      "Umbraco.BlockList":[
         {
            "contentUdi":"umb://element/0da576e5fc7445bd9d789c5ee9fe9c54",
            "settingsUdi":"umb://element/7073a102dbcc487986962a3d51820de7"
         },
         {
            "contentUdi":"umb://element/c6e23e8137d24b409bb5ef41bdb705b9",
            "settingsUdi":"umb://element/0467ceb158cc49a1acfd1516f63eccf6"
         }
      ]
   },
a
Hi @jacksorjacksor (Richard Jackson) Either UDI just have to end with a random GUID that doesn't collide with anything. So something like
new GuidUdi(Constants.UdiEntityType.Element, Guid.NewGuid())
should suffice.
j
HI @Anders Bjerner, Oh I misunderstood what those UDIs represented. I thought they were linked to a specific content row type (i.e. "contentUdi":"umb://element/0da576e5fc7445bd9d789c5ee9fe9c54" was specifically linked to a specific Block List type. Thank you.
a
To elaborate a bit, the
contentUdi
has to match the UDI that you're specifying for the corresponding item in the
contentData
array. Similar goes for settings. But the UDIs doesn't refer to anything outside the block list model.
j
Ah that makes sense - if I'm understanding you correctly, I've included screenshots showing where the UDIs are referenced. That leads me to believe that my actual question should have been in relation to the field "contentTypeKey", which in the [docs example](https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor#creating-blocklist-programmatically) appears to be implying that
"contentTypeKey":"aca1158a-bad0-49fc-af6e-365c40683a92"
is referring to either the
People
property/block list editor or the
Person
document type which is created by
People
- but I'm unsure of which. My other follow-up in this specific area is that the [two C# examples after the JSON file](https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor#creating-blocklist-programmatically) never actually parse the JSON file, so I'm confused as to the relationship between the three code snippets.
a
I'd say the docs are misleading as you typically wouldn't use the same element type for both the content part and the settings part.
j
Ah. In which case... I don't really know what to do?
a
It depends on how you have configured the block list. For instance for the site I'm currently working on, I have a YouTube block there the content part then is my YouTube element type with properties for entering misc information about the video, and then the settings part is a more common settings element - eg. for hiding a block. Most of the blocks use our General Block Settings for the settings part, but they don't all have to. So to answer your question, each block item that you add should match the configuration for that block.
j
Yeah that's exactly how I'm working, including making a YouTube block. How do you get the "contentTypeKey" or any reference ID, for the specific "YouTube" or "General Block Settings" element types? But yes, the end goal is to be able to use the Content Service to create block list content with various different blocks (eight in total), and I'm struggling to understand how to create specific blocks with specific content - fitting into my post on [the forum](https://our.umbraco.com/forum/using-umbraco-and-getting-started/112591-create-content-programmatically-or-where-do-you-just-run-code). (For reference I've specifically asked folks going to CodeCabin to help me with this too!)
a
Unfortunately there isn't a straightforward way to get the GUID key of a document/element via the UI in Umbraco. Are you using ModelsBuilder btw?
j
Yes I am using ModelsBuilder
a
Ok. I have my own logic that makes this a bit easier. Eg. here I'm creating a new YouTube block. The generated model for my YouTube block is called
HfYouTubeBlock
, and referencing this via a generic parameter, my underlying logic will automatically find the correct GUID key. On the plus side, there is then also intellisense for the properties of said model.
The models are available in our migrations package: https://github.com/limbo-works/Limbo.Umbraco.Migrations/tree/v1/main/src/Limbo.Umbraco.Migrations/Models/BlockList But I'll likely move them to one our other packages, and so the logic isn't dependant on our migration setup. I can try looking into that. Alternatively you have to find the GUID key manually via the database or via the
IContentService
. Which can be a pain.
j
Oh wow, brilliant. I'll look into that when I'm not in a meeting!
a
Just remembered - my Iddqd package adds a content app for document types so that the GUID key is accessible via the UI: https://github.com/abjerner/Limbo.Umbraco.Iddqd#info-content-app
j
Incredible, thank you!
s
Okay, got to ask:
Iddqd
??
j
"Coincidentally iddqd is the Doom cheat code for invulnerability - also known as god mode."
a
@Sebastiaan sounds like you haven't played Doom 😱
or haven't cheated
s
Aaahhh!! Wow blast from the past!
I certainly have done both 😅 😂
j
Thanks iddqd
Just as a quick update - IDDQD has been brilliant for helping with various elements and it's a new must-have extension, so thank you @Anders Bjerner. Making good progress on this, and once I've managed it I would very much like to review/update the documentation around this.
m
@Anders Bjerner Any chance the Youtube package could be bumped up to support 13?
just the max support I mean
put up an issue already 🙂
a
@marcusjmsweden not sure about an ETA yet. I have a few weeks of from work now for the Holidays, so might first look at it in the new year. Could also be that I get bored and look at packages anyways.
m
Hoping for the last then ;). Great package. I just use it directly now but it is easier to maintain as a package.
I dont see any other issues just in case you wonder
2 Views