Delete only relationship and not teh entity record RRS feed

  • Question

  • I have a 1:N relationship between a custom entity and contact. If I delete/deactivate a contact in the relationship, the contact record itself gets deleted/deactivated. How do I delete only the relatioship between the custom entity record and the contact record without affecting the contact record itself ?
    Tuesday, February 9, 2010 12:46 AM


All replies

  • More info: the existing relationship behavior is 'Referential'.

    Tuesday, February 9, 2010 1:07 AM
  • Just remove the lookup value.

    Tuesday, February 9, 2010 4:52 AM
  • Where? Using plugin? or in javascript? If javascript, how do I capture that event ?
    Tuesday, February 9, 2010 5:05 PM
  • On contact entity should be lookup field pointing to the related entity. If you didn't add this attribute to form, than do it. 

    So now on contact form you have lookup field pointing to related entity. Just remove value from the lookup.

    David Kolodziejczyk
    Tuesday, February 9, 2010 5:11 PM
  • But the user deletes it in the following way:

    1) Goes to the custom entity record
    2) Clicks on 'Relationship' in the left nav to see all teh contacts associated with teh custom entity
    3) Clicks on the delete button 'X' on the menu, or says deactivate. Both these operations deletes/deactivates the contact record

    Tuesday, February 9, 2010 5:18 PM
  • Yes, that's how it works. 

    If you want to remove relationship you have to remove value from lookup field on contact form. 

    You can also add button on contact grid, that will call javascript function which will remove the relationship beetwen selected contacts and your custom entity.

    David Kolodziejczyk
    Tuesday, February 9, 2010 5:22 PM
  • Hi Dawid, I understand your concept but not the method to be followed. Apologies! My question is this:

    The user does not go into the contact form. Instead he goes to the custom entity form. There, on the left nav below 'Information','Activities','History' and 'Workflows', he sees 'Contacts' and clicks on the 'Contacts' link, which takes him to a grid that lists all contacts for that custom record. Do you say the only way is to add a button to this grid ? If so, should it be done in the ISV config ? How do I capture the custom record Id in the javascript ?
    Tuesday, February 9, 2010 5:30 PM
  • You don't need your custom record id, you just need selected contacts ids.

    Use this sample to get selected contacts ids
    Walkthrough: Capturing the GUID Values of Records Selected in a Grid

    That use webservice call to remove lookup value from contacts:

    Client-side Web Service Calls for Microsoft Dynamics CRM 4.0: Calling the CRM Service with Javascript

    Accessing Microsoft Dynamics CRM Web Services

    David Kolodziejczyk
    Tuesday, February 9, 2010 5:40 PM
  • Hi David,

    I understand the concepts shown in those examples, but I'm not sure I'm strong enough in XML and Javascript to merge them into my own script. Similarly to Glora, I have created a 1:N relationship between Opportunity and Contact, and my users add and delete associated Contacts via the Opportunity window. I don't want them to delete Contacts, but currently there is no way to 'remove' from the list, like there is in an N:N relationship (for example, Competitors and Opportunity). I would like to create a "Remove" button by customizing the ISV.config.

    Can you provide any other examples that might show this scenario in specific. Glora, did you have sucess in creating this code?

    Thank you!

    - Caitlin Young

    Monday, May 3, 2010 9:00 PM
  • I can prepare js script for you tomorrow (it's 1 am in Poland).

    Good night.



    David Kolodziejczyk
    Monday, May 3, 2010 10:53 PM
  • <Entity name="contact">
            <Button Icon="/_imgs/ico_18_debug.gif" JavaScript="            
                var oType = crmGrid.GetParameter('oType');
                if(oType == 3)
    							var a = document.all['crmGrid'].InnerGrid.SelectedRecords; 
    							var selectedItems = new Array(a.length);
    							for (var i=0; i &lt; a.length; i++) 
    								selectedItems[i] = a[i][0];								
    								var contactId = a[i][0];
    								var newValue = '';
    								var authenticationHeader = GenerateAuthenticationHeader();								
    								// Prepare the SOAP message.
    								var xml = &quot;&lt;?xml version='1.0' encoding='utf-8'?&gt;&quot; + 
    								&quot;&lt;soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&quot;+
    								&quot; xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'&quot;+
    								&quot; xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;&quot;+ 
    								&quot;&lt;Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'&gt;&quot;+ 
    								&quot;&lt;entity xsi:type='contact'&gt;&quot;+ 
    								// Prepare the xmlHttpObject and send the request.
    								var xHReq = new ActiveXObject('Msxml2.XMLHTTP');
    								xHReq.Open('POST', '/mscrmservices/2007/CrmService.asmx', false);
    								xHReq.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    								xHReq.setRequestHeader('Content-Length', xml.length);
    								// Capture the result
    								var resultXml = xHReq.responseXML;
    								// Check for errors.
    								var errorCount = resultXml.selectNodes('//error').length;
    								if (errorCount != 0)
    									var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
    								// Display a confirmation message and open the updated contact.														
                 alert('You can remove relationship between Opportunity and Contact');
                } " Client="Web">
              <Title LCID="1033" Text="Remove from the list" />
              <ToolTip LCID="1033" Text="Remove from the list" />

    David Kolodziejczyk
    Wednesday, May 5, 2010 9:36 AM