다음을 통해 공유


How to easily close many CRM 4.0 activities in one shot ?

This sample allows you to add a button in order to close selected activities
in one shot.

image

Install:

- Export the ISV config file.

- extract the file and open it in an text editor.

- Update the isv config file with this source code (‘activitypointer’ section )

<ImportExportXml version="4.0.0.0" languagecode="1033" generatedBy="OnPremise">

  <Entities>

  </Entities>

  <Roles>

  </Roles>

  <Workflows>

  </Workflows>

  <IsvConfig>

    <configuration version="3.0.0000.0">

      <Root>

      </Root>

      <!-- Microsoft Customer Relationship Management Entities (Objects) -->

      <Entities>

        <Entity name="activitypointer">

          <Grid>

            <MenuBar>

              <Buttons>

                <Button Icon="/_imgs/ico_18_debug.gif" JavaScript="

                        var grid = document.getElementById('gridBodyTable');

                        var a = document.all['crmGrid'].InnerGrid.SelectedRecords;

                        var selectedItems = new Array(a.length);

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

                        {

                        var stateReq = '';

                        var stateType = '';

                        var state = 'Completed';

                        var status = '-1';

                         if(a[i][1] == '4212')

                         {

                          stateReq = 'SetStateTaskRequest';

                          stateType= 'Task';

                          }

                        else if(a[i][1] == '4210')

                         {

                          stateReq = 'SetStatePhoneCallRequest';

                          stateType= 'PhoneCall';

                          }

                        else if(a[i][1] == '4207')

                         {

                          stateReq = 'SetStateLetterRequest';

                          stateType= 'Letter';

                        }

                        else if(a[i][1] == '4204')

                         {

                          stateReq = 'SetStateFaxRequest';

                          stateType= 'Fax';

                        }

                        else if(a[i][1] == '4214')

                         {

                          stateReq = 'SetStateServiceAppointmentRequest';

                          stateType= 'ServiceAppointment';

                          state = 'Closed';

                        }

                        else if(a[i][1] == '4201')

                         {

                          stateReq = 'SetStateAppointmentRequest';

                          stateType= 'Appointment';

                        }

                       else if(a[i][1] == '4402')

                         {

                          stateReq = 'SetStateCampaignActivityRequest';

                          stateType= 'CampaignActivity';

                          state = 'Closed';

                        }

                       else if(a[i][1] == '4401')

                         {

                          stateReq = 'SetStateCampaignResponseRequest';

                          stateType= 'CampaignResponse';

                       }

                       else if(a[i][1] == '4202')

                         {

                          stateReq = 'SetStateEmailRequest';

                          stateType= 'Email';

                        }

                            var xml = '' +

'&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>' +

                            '&lt;soap:Envelope xmlns:soap=&quot;https://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;https://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;https://www.w3.org/2001/XMLSchema&quot;>' +

                            '  &lt;soap:Header>' +

                            '    &lt;CrmAuthenticationToken xmlns=&quot;https://schemas.microsoft.com/crm/2007/WebServices&quot;>' +

                            '      &lt;AuthenticationType xmlns=&quot;https://schemas.microsoft.com/crm/2007/CoreTypes&quot;>0&lt;/AuthenticationType>' +

                            '      &lt;OrganizationName xmlns=&quot;https://schemas.microsoft.com/crm/2007/CoreTypes&quot;>Microsoft&lt;/OrganizationName>' +

                            '      &lt;CallerId xmlns=&quot;https://schemas.microsoft.com/crm/2007/CoreTypes&quot;>00000000-0000-0000-0000-000000000000&lt;/CallerId>' +

                            '    &lt;/CrmAuthenticationToken>' +

                            '  &lt;/soap:Header>' +

                            '  &lt;soap:Body>' +

                            '    &lt;Execute xmlns=&quot;https://schemas.microsoft.com/crm/2007/WebServices&quot;>' +

                            '      &lt;Request xsi:type=&quot;'+stateReq+'&quot;>' +

                            '        &lt;EntityId>' + a[i][0] + '&lt;/EntityId>' +

                            '        &lt;'+stateType+'State>'+state+'&lt;/'+stateType+'State>'+

                            '        &lt;'+stateType+'Status>' +  status + '&lt;/'+stateType+'Status>'+

                            '    &lt;/Request>' +

                            '    &lt;/Execute>' +

                            '  &lt;/soap:Body>' +

                            '&lt;/soap:Envelope>' +

                            '';

                            var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');

                            xmlHttpRequest.Open('POST', '/mscrmservices/2007/CrmService.asmx', false);

                            xmlHttpRequest.setRequestHeader('SOAPAction','https://schemas.microsoft.com/crm/2007/WebServices/Execute');

                            xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');

                            xmlHttpRequest.setRequestHeader('Content-Length', xml.length);

                            xmlHttpRequest.send(xml);

                            var resultXml = xmlHttpRequest.responseXML;                       

                        }

                        window.crmGrid.Refresh();

" Client="Web" AvailableOffline="true">

                  <Titles>

                    <Title LCID="1033" Text="Close Activities" />

                  </Titles>

                  <ToolTips>

                    <ToolTip LCID="1033" Text="Close Activities for selected records" />

                  </ToolTips>

                </Button>

              </Buttons>

            </MenuBar>

          </Grid>

        </Entity>

      </Entities>

    </configuration>

  </IsvConfig>

  <EntityMaps />

  <EntityRelationships />

  <Languages>

    <Language>1033</Language>

  </Languages>

</ImportExportXml>

-import in CRM the isv config file.

 

Pierre-Adrien FORESTIER | PAF | https://blogs.msdn.com/paf

Comments

  • Anonymous
    September 08, 2010
    This is just what I am looking for, but when I tried it I got prompted for an authentication dialogue for each record in the grid.  Is there something else I need to do to get it to work?

  • Anonymous
    November 01, 2010
    Replace the soap header with GenerateAuthenticationHeader().

  • Anonymous
    February 08, 2011
    The easiest way I've found is to create an on demand workflow for each activity type and run the work flow on selected records to set the status to completed.

  • Anonymous
    December 24, 2011
    Fantastic very clever way of implementing Thanks for the post