SharePoint Custom Field - is it possible to handle item deletion event? - sharepoint

I'm expanding SPFieldText and BaseFieldControl to create a custom field. The field saves some data externally (for example, on a database or on another list)
Within the control I'm able to handle Edit and New events (using ControlMode).
I'd like to run a function and clean up some data when an item containing my field is deleted. Is this possible, in the context of a custom field?

No, the field has no "knowledge" of the item it is contained in. You could however perform the cleanup by creating an ItemEventReceiver.

Related

How to force creation of new ContentPartRecords for existing content items?

I have created a new ContentPart with a ContentPartRecord in a custom module and attached it to an existing content type on my website that already has hundreds of content items.
Now when I perform queries of the format contentManager.Query<MyPart, MyPartRecord>().List() I don't get any results since no MyPartRecords actually exist in the database yet.
Is there a way to make sure this happens for all content as soon as my part gets attached to a content type, or will I have to manually interact with all of the items before they become queryable?
This query is asking for all content items that have that part, which is not the case of items created before you added the part to the type definition. See the type definition as a blueprint more than a schema. Depending on what exactly you're trying to do, you may want to try to query by content type instead.
The part will get attached next time the item gets updated, pretty much. You could build something that scripts the operation on existing items, but nothing out of the box will do that.

How to add value to a field from another lookup field?

I have a custom entity Partnership in which I have one lookup field contacts.
now I want to add the name field value of the partnership from contact fullname in time of creation of Partnership.
is it possible with the help of pre-existing configuration settings,(without plugin or web resource)
Thanks.
Without using a plug-in or web resource you have a couple options.
1- You can configure the mappings between the 2 entities by going to the Entity (contact) -> Relationship -> Mappings -> and add a new mapping there. For this to work though, you will need to create the child record from the subgrid of the contact, and if the contact changes it won't update the values. So it may or may not be an ideal solution for you.
2- You can create a workflow rule that runs on create and/or update of the Partnership record that pulls the value from the parent contact onto the partnership record. The downside of this is that workflows are async so you won't see the update for a few seconds and refresh the Partner record.
Hope this helps.
If you want to be able to click the "New Partnership" button in the CRM ribbon, then select a contact, and have the name of the contact, be used to populate another field on the form, you will have to use JavaScript. There is no configurable way of doing it.
If you'd like the value to be populated before it is saved in the CRM database, you could use JavaScript, or a custom Plugin. If you'd like the value to be updated after the record is created, you could use a workflow.
You'll have to use one of those three methods to populate the field. The real question I have though, is why are you bothering to populate the field in the first place? You can add the full Contact name to any view, so I don't see a real big reason to include it.

Marking a Form Element as Required Inside an EventSubscriber in symfony2

I have an entity with a member called 'mediaType', which tells me which of two other members to pull data from. When I'm building the form to create the entity, I have mediaType as a drop down and then two text fields for the other two members. What I want to do is force one or the other two fields to be required based on the mediaType selected (or neither, if the user select None. I'll handle hiding the fields with JS).
Since I'm manipulating the form after binding, I set up an EventSubscriber to listen on the PostBind event. My subscriber fires just fine, but I'm at a loss to figure out how to mark one of the fields as required. I can get the field, and I can check to see if it is required, but I just don't know how to make it required.
Is there a way to do this? Or is there a better way than using EventSubscriber?
You could use validations groups http://symfony.com/doc/current/book/forms.html#book-forms-validation-groups see "Groups based on Submitted Data"

Filtering a nested repeat

My application has documents for Companies, and for Clients. This is a many to many relationship; a company can have any number of clients, and a client can be a client of many companies. The relationships are stored by creating a response document to the company, with a field containing the ID of the client document.
I would like to be able to show fields from the client document on the company's XPage, and I've been trying to do this with repeat controls. I created a view of all the link documents, and used that to create a repeat, filtering it with the current document ID to collect all the links that the current company has. This allows me to list all the IDs of the client documents associated with that company.
I have been trying to work out how to pass this ID to a repeat control nested within the first one, either to use it as a filter on a view of all the client documents, or to use it as the data source document ID directly. Is this possible? If not, how would I go about showing data from the client document on the company page?
When you specify a repeat control you specify the variable that contains the instance value. This variable name is visible to anything inside the repeat control. So your variable would contain the UNID of the client documents one at a time. E.g you call it ClientDocID. You put a panel inside that repeat control. That panel can have its own DominoDocument data source. The datasource can have new, display or edit as default action. You pick "display" which requires a DocumentId to be provided. Select "computed" and simply use ClientDocID as formula.
You can suppress rendering of HTML for the panel (check the properties), so it would fit e.g. inside a xp:tr.
Hope that helps

Word and Custom Content Types

I have defined a new content type (document) for sharepoint. The problem I have is that word automatically comes up with window allowing updating of these properties (for example effective date) that is not validated and I don't want it to show when the user is uploading changes (I fill in some of these fields on the updated method in the eventreceiver class). Is it possible to disable this or at least customize the word behavior?
You can create your own Document Information Panels: http://msdn.microsoft.com/en-us/library/bb684925.aspx.
Another alternative might be to set the ShowInNewForm/ShowInEditForm properties of the SPField. But im not sure if Word uses them.

Resources