Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have an umbraco 7 instance.
I have a doc type to witch I have added a checkbox (true/false) data type. What I want to do is if the user checks this and save and publishes i want to the run some custom server code.
The only way I can think of doing this would be to remove the built in checkbox and replace it with a custom built angularjs one which in turn will use an ajax call to an umbraco web api method which will in turn run some server code.
My question is is this the only/best appraoch?
You probably want to hook into the Content Service Saved event. From there, you'll be able to run some code based on what an editor is saving:
public class CustomEventHandler : ApplicationEventHandler
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
ContentService.Saved += delegate(IContentService sender, SaveEventArgs<IContent> args)
foreach (var content in args.SavedEntities)
// Some custom logic when checked
Would this code run every time any page was saved and not just for pages of a specific doc type?
Yeah it does but you could change you foreach statement to only loop through pages of a certain document type:
foreach (var content in args.SavedEntities.Where(c => c.ContentType.Alias.Equals("documentTypeAliasWithCheckboxOn")))
yeah seems like a good alternative for what im trying to achieve. For convention what folder would you keep these classes in?
One other last question i dont know how much experience you have with custom data types and angularjs but is the only way to run server side code from angularjsby making ajax calls to umbraco web api.
You can put the classes where ever you like really. An Events folder might be good place.
I've not tried what you want but I'm guessing you'll want to write an Umbraco Web API Service to be triggered from your custom data type when updated.
Yeah thats exactly what I thought.
thanks for the help.
No worries. Glad I could help :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted