Enforce Unique ID field for content item

Posted by Community Admin on 04-Aug-2018 17:37

Enforce Unique ID field for content item

All Replies

Posted by Community Admin on 22-Mar-2013 00:00

Is there way to enforce a field to be 'unique'. I have a requirement where I have a 'Projects' module. Each content item will have a 'ProjectID'. I want to enforce uniqueness of this field; however the field is manually entered via the UI by the user (cannot be a GUID). Example: ProjectID = 123-33-4. Prior to having the item created, I would like to check that there is no pre-existing project in the system with that same ProjectID. I can't seem to find where/how this can be done...
I thought perhaps there would be an event I could tap into to do a query, but there doesn't appear to be one...
there is no 'IDynamicContentCreatingEvent' that triggers ahead of time that the actual item is created
, there's only the 'created' event...
EventHub.Subscribe<IDynamicContentCreatedEvent>(evt => CRD.Sitefinity.CustomDecorator.BusinessOpportunitiesDecorator.ContentCreatedEventHandler(evt));

Ideas?

Posted by Community Admin on 27-Mar-2013 00:00

Hello Rico,

You can use the OpenAccess provider implementation which would allow you to subscribe to the Manager.Executing event which gets fired prior to committing the transaction:

protected void Application_Start(object sender, EventArgs e)
        
            Bootstrapper.Initialized += Bootstrapper_Initialized;
        
 
        void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
        
            DynamicModuleManager.Executing += new EventHandler<ExecutingEventArgs>(DyamicContentProvider_Executing);
        
 
        protected void DyamicContentProvider_Executing(object sender, ExecutingEventArgs args)
        
            if (!(args.CommandName == "CommitTransaction" || args.CommandName == "FlushTransaction"))
                return;
            var provider = sender as DynamicModuleDataProvider;
            foreach (var item in provider.GetDirtyItems())
            
                SecurityConstants.TransactionActionType itemStatus = provider.GetDirtyItemStatus(item);
                if (itemStatus == SecurityConstants.TransactionActionType.New || itemStatus == SecurityConstants.TransactionActionType.Updated)
                
                    if (item is DynamicContent)
                    
                        //do something here
                    
                
            
        




Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed