Copied to clipboard

Flag this post as spam?

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


  • Max 80 posts 437 karma points
    Jun 06, 2017 @ 14:17
    Max
    0

    Generate document type item name from properties in document type

    I'd like to generate a custom document type item name based on the values from a field in the document type. In this case we have repeated monthly board meetings whereby several committees/sub-committees meet regularly on the day of the board meeting.

    I want to create a record for each board meeting day:

    Meeting 1 (today - parent document type)
      - committee 1 - 9:30am (child)
      - committee 2 - 10:30am (child)
    Meeting 2 (tomorrow)
     - committee 1 - 10am
     - committee 2 - 11am
     - committee 3 - 12pm
    Meeting 3 (next month)
     - committee 1 - 11am
     - committee 3 - 12pm
     - committee 4 - 2pm
    

    A meeting has a scheduled day, and a checkbox for cancelled. I would like the name to default "Document Type Alias - [scheduled date/time]".

    eg. Meeting 1 - [todays date from property editor]

    Committee meeting document type name would then be defaulted "Committee name - [start date/time from property editor]"

    We shouldn't have to manually name both the meeting and the individual committee/sub-committee records.

    Can I accomplish this by hijacking the document type configuration/creation or do HAVE to create a custom section and then template that?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 08, 2017 @ 06:55
    Kevin Jump
    0

    Hi,

    You can use Content Service Events to make changes when a node is saved/published.

    You could use this to take the value out of the property within a content node and use it to set the name of the node. this should do what you need to do.

    I think you just need to make sure that when you save any changes via the ContentService that you set raiseEvents = false or you will call the save event again and get caught in a loop.

  • Max 80 posts 437 karma points
    Jun 08, 2017 @ 18:13
    Max
    0

    ok. I've got a events class created to catch the saving event... I don't want to act on all of my content types... is there a specific way or best practice for attaching to only specific document/content types?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 08, 2017 @ 18:45
    Kevin Jump
    0

    Hi

    it is usually best to test for the content type of the entity and then see if that matches the one you are looking for.

    for performance you want to compare the id not the actual type (going to the type hits the db), so you should load the type id into a class variable in the applicationStarted call:

            var myContentType = applicationContext.Services.ContentTypeService.GetContentType("doctypealias");
            if (myContentType != null)
               myContentTypeId = myContentType.Id;
    

    and then compare on the save event:

    foreach (var item in e.SavedEntities)
    {
      if (item.contentTypeId == myContentTypeId) {
          // do the business 
      }
    }
    
  • Max 80 posts 437 karma points
    Jun 08, 2017 @ 19:38
    Max
    0

    catch 22... can't NOT put something in the content type name field...unless I can catch the form validation before the request is sent to actually save the document...can I override form validation too? (client side validation)

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 08, 2017 @ 19:48
    Kevin Jump
    0

    have you tried using Saving event rather than the Saved one?

  • Max 80 posts 437 karma points
    Jun 08, 2017 @ 19:53
    Max
    0

    Yeah, That was what I hooked to first.

    If I put gibberish in and then process the record it works... I need to gain access to the client side form validation to ignore the "required" attribute on the "headerName" input for the document type...

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jun 08, 2017 @ 19:57
    Kevin Jump
    0

    Hi

    it really doesn't feel right - an a bit hacky - but i am not 100% sure (without knocking some code up) what your options are.

    you can look at intercepting the code / logic in angular - if you follow some of the code in this: https://24days.in/umbraco-cms/2015/umbraco-7-back-office-tweaks/

    but I would be considering my options at this point. maybe use a list view that lists the nodes by a property (like a title or something) then you don't need to worry about the name?

Please Sign in or register to post replies

Write your reply to:

Draft