Thursday, May 27, 2010

Delete teams button in Microsoft Dynamics CRM 4.0

There was question on AxForum - why it is not possible to delete team through interface. One of visitors - slivka_83 suggested to use SDK and Delete message. I've decided to make ISV.Customization which will add Delete button to Team grid.



        <Entity name="team">

          <Grid>

            <MenuBar>

              <Buttons>

                <Button Icon="/_imgs/ico_16_delete.gif" JavaScript = "var teams = getSelected('crmGrid');



for (var i = 0; i &lt; teams.length; i++)

{

    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;+

    GenerateAuthenticationHeader()+

    &quot;&lt;soap:Body&gt;&quot;+

    &quot;&lt;Delete xmlns='http://schemas.microsoft.com/crm/2007/WebServices'&gt;&quot;+

    &quot;&lt;entityName&gt;team&lt;/entityName&gt;&quot;+

    &quot;&lt;id&gt;&quot; + teams[i] + &quot;&lt;/id&gt;&quot;+

    &quot;&lt;/Delete&gt;&quot;+

    &quot;&lt;/soap:Body&gt;&quot;+

    &quot;&lt;/soap:Envelope&gt;&quot;;



    var xHReq = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);

    xHReq.Open(&quot;POST&quot;, &quot;/mscrmservices/2007/CrmService.asmx&quot;, false);

    xHReq.setRequestHeader(&quot;SOAPAction&quot;,&quot;http://schemas.microsoft.com/crm/2007/WebServices/Delete&quot;);

    xHReq.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml; charset=utf-8&quot;);

    xHReq.setRequestHeader(&quot;Content-Length&quot;, xml.length);

    xHReq.send(xml);

}



crmGrid.Refresh();">


                  <Titles>

                    <Title LCID="1033" Text="Delete" />

                  </Titles>

                  <ToolTips>

                    <ToolTip LCID="1033" Text="Delete Selected Teams" />

                  </ToolTips>

                </Button>

              </Buttons>

            </MenuBar>

          </Grid>

        </Entity>