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:
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.
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?
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
}
}
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)
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...
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?
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:
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?
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.
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?
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:
and then compare on the save event:
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)
have you tried using
Saving
event rather than theSaved
one?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...
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?
is working on a reply...