Thursday, August 13, 2015

Import Same Database with Different Name in CRM 2011/13/15

Hi All,

Please find the SQL Script. Run the Script in the Imported Database\

DECLARE @OldOrganizationId uniqueidentifier, @NewOrganizationId uniqueidentifier
 -- The Old OrganizationId
 SET @OldOrganizationId = (SELECT TOP(1) OrganizationId FROM OrganizationBase)
 -- The New OrganizationId
 SET @NewOrganizationId = (SELECT NEWID())
 --PRINT @OldOrganizationId
 --PRINT @NewOrganizationId
 -- Table with all Found Columns with the OrganizationId
 DECLARE @FoundOrganizationIds TABLE (Id bigint identity(1,1), TableName nvarchar(max), ColumnName nvarchar(max), ColumnValue nvarchar(max))

 -- Table with all uniqueidentifier Columns in the Database
 DECLARE  @FoundUniqueIdentifierColumns TABLE(Id bigint identity(1,1), TableName nvarchar(max), ColumnName nvarchar(max))

 -- Search for all uniqueidentifier Columns in the Database
 INSERT INTO @FoundUniqueIdentifierColumns
 SELECT
   col.TABLE_NAME, col.COLUMN_NAME
 FROM
  INFORMATION_SCHEMA.TABLES tbl INNER JOIN
  INFORMATION_SCHEMA.COLUMNS col ON tbl.TABLE_NAME = col.TABLE_NAME
 WHERE
  tbl.TABLE_TYPE = 'BASE TABLE' AND
  col.DATA_TYPE IN ('uniqueidentifier')
 DECLARE @ColumnCount bigint
 SET @ColumnCount = (SELECT COUNT(*) FROM @FoundUniqueIdentifierColumns)
 -- PRINT CAST(@ColumnCount as nvarchar)

 DECLARE @Iterator bigint
 SET @Iterator = 1

 -- Look through all found uniqueidentifier for the Old OrganizationId Columns and Save the TableName/ColumnName in @FoundOrganizationIds
 WHILE @Iterator <= @ColumnCount
  BEGIN
   DECLARE @execsql nvarchar(max)
   DECLARE @TableName nvarchar(max)
   DECLARE @ColumnName nvarchar(max)
  
   SET @TableName = (SELECT TableName FROM @FoundUniqueIdentifierColumns WHERE Id = @Iterator)
   SET @ColumnName = (SELECT ColumnName FROM @FoundUniqueIdentifierColumns WHERE Id = @Iterator)
  
   --PRINT(@TableName)
   --PRINT(@@ColumnName)
  
   SET @execsql = 'SELECT DISTINCT ' + CHAR(39) + @TableName + CHAR(39) + ','
   SET @execsql = @execsql + CHAR(39) + @ColumnName + CHAR(39) + ','
   SET @execsql = @execsql + @ColumnName
   SET @execsql = @execsql + ' FROM '
   SET @execsql = @execsql + @TableName
   SET @execsql = @execsql + ' WHERE '
   SET @execsql = @execsql + @ColumnName
   SET @execsql = @execsql + ' = ' + CHAR(39) + CAST(@OldOrganizationId as varchar(50)) + CHAR(39)
  
   INSERT INTO @FoundOrganizationIds (TableName, ColumnName, ColumnValue)
   -- PRINT (@execsql)
   EXEC (@execsql)
  
   SET @Iterator = @Iterator + 1  
  END
 -- SELECT * FROM @FoundOrganizationIds
 DECLARE @ColumnIterator bigint, @ColumnTotal bigint
 SET @ColumnIterator = 1
 SET @ColumnTotal = (SELECT COUNT(id) FROM @FoundOrganizationIds)

 PRINT (@ColumnTotal)

 -- INSERT New Organization in the OrganizationTable with the new OrganizationId (Copy of the Old Organization but with the new Id)
 INSERT INTO [dbo].[OrganizationBase]
           ([OrganizationId]
           ,[Name]
           ,[UserGroupId]
           ,[PrivilegeUserGroupId]
           ,[FiscalPeriodType]
           ,[FiscalCalendarStart]
           ,[DateFormatCode]
           ,[TimeFormatCode]
           ,[CurrencySymbol]
           ,[WeekStartDayCode]
           ,[DateSeparator]
           ,[FullNameConventionCode]
           ,[NegativeFormatCode]
           ,[NumberFormat]
           ,[IsDisabled]
           ,[DisabledReason]
           ,[KbPrefix]
           ,[CurrentKbNumber]
           ,[CasePrefix]
           ,[CurrentCaseNumber]
           ,[ContractPrefix]
           ,[CurrentContractNumber]
           ,[QuotePrefix]
           ,[CurrentQuoteNumber]
           ,[OrderPrefix]
           ,[CurrentOrderNumber]
           ,[InvoicePrefix]
           ,[CurrentInvoiceNumber]
           ,[UniqueSpecifierLength]
           ,[CreatedOn]
           ,[ModifiedOn]
           ,[FiscalYearFormat]
           ,[FiscalPeriodFormat]
           ,[FiscalYearPeriodConnect]
           ,[LanguageCode]
           ,[SortId]
           ,[DateFormatString]
           ,[TimeFormatString]
           ,[PricingDecimalPrecision]
           ,[ShowWeekNumber]
           ,[NextTrackingNumber]
           ,[TagMaxAggressiveCycles]
           ,[TokenKey]
           ,[SystemUserId]
           ,[CreatedBy]
           ,[GrantAccessToNetworkService]
           ,[AllowOutlookScheduledSyncs]
           ,[AllowMarketingEmailExecution]
           ,[SqlAccessGroupId]
           ,[CurrencyFormatCode]
           ,[FiscalSettingsUpdated]
           ,[ReportingGroupId]
           ,[TokenExpiry]
           ,[ShareToPreviousOwnerOnAssign]
           ,[AcknowledgementTemplateId]
           ,[ModifiedBy]
           ,[IntegrationUserId]
           ,[TrackingTokenIdBase]
           ,[BusinessClosureCalendarId]
           ,[AllowAutoUnsubscribeAcknowledgement]
           ,[AllowAutoUnsubscribe]
           ,[Picture]
           ,[TrackingPrefix]
           ,[MinOutlookSyncInterval]
           ,[BulkOperationPrefix]
           ,[AllowAutoResponseCreation]
           ,[MaximumTrackingNumber]
           ,[CampaignPrefix]
           ,[SqlAccessGroupName]
           ,[CurrentCampaignNumber]
           ,[FiscalYearDisplayCode]
           ,[SiteMapXml]
           ,[IsRegistered]
           ,[ReportingGroupName]
           ,[CurrentBulkOperationNumber]
           ,[SchemaNamePrefix]
           ,[IgnoreInternalEmail]
           ,[TagPollingPeriod]
           ,[TrackingTokenIdDigits]
           ,[NumberGroupFormat]
           ,[LongDateFormatCode]
           ,[UTCConversionTimeZoneCode]
           ,[TimeZoneRuleVersionNumber]
           ,[CurrentImportSequenceNumber]
           ,[ParsedTablePrefix]
           ,[V3CalloutConfigHash]
           ,[IsFiscalPeriodMonthBased]
           ,[LocaleId]
           ,[ParsedTableColumnPrefix]
           ,[SupportUserId]
           ,[AMDesignator]
           ,[CurrencyDisplayOption]
           ,[MinAddressBookSyncInterval]
           ,[IsDuplicateDetectionEnabledForOnlineCreateUpdate]
           ,[FeatureSet]
           ,[BlockedAttachments]
           ,[IsDuplicateDetectionEnabledForOfflineSync]
           ,[AllowOfflineScheduledSyncs]
           ,[AllowUnresolvedPartiesOnEmailSend]
           ,[TimeSeparator]
           ,[CurrentParsedTableNumber]
           ,[MinOfflineSyncInterval]
           ,[AllowWebExcelExport]
           ,[ReferenceSiteMapXml]
           ,[IsDuplicateDetectionEnabledForImport]
           ,[CalendarType]
           ,[SQMEnabled]
           ,[NegativeCurrencyFormatCode]
           ,[AllowAddressBookSyncs]
           ,[ISVIntegrationCode]
           ,[DecimalSymbol]
           ,[MaxUploadFileSize]
           ,[IsAppMode]
           ,[EnablePricingOnCreate]
           ,[IsSOPIntegrationEnabled]
           ,[PMDesignator]
           ,[CurrencyDecimalPrecision]
           ,[MaxAppointmentDurationDays]
           ,[EmailSendPollingPeriod]
           ,[RenderSecureIFrameForEmail]
           ,[NumberSeparator]
           ,[PrivReportingGroupId]
           ,[BaseCurrencyId]
           ,[MaxRecordsForExportToExcel]
           ,[PrivReportingGroupName]
           ,[YearStartWeekCode]
           ,[IsPresenceEnabled]
           ,[IsDuplicateDetectionEnabled]
           ,[RecurrenceExpansionJobBatchInterval]
           ,[DefaultRecurrenceEndRangeType]
           ,[HashMinAddressCount]
           ,[RequireApprovalForUserEmail]
           ,[RecurrenceDefaultNumberOfOccurrences]
           ,[ModifiedOnBehalfBy]
           ,[RequireApprovalForQueueEmail]
           ,[AllowEntityOnlyAudit]
           ,[IsAuditEnabled]
           ,[RecurrenceExpansionSynchCreateMax]
           ,[GoalRollupExpiryTime]
           ,[BaseCurrencyPrecision]
           ,[FiscalPeriodFormatPeriod]
           ,[AllowClientMessageBarAd]
           ,[InitialVersion]
           ,[HashFilterKeywords]
           ,[NextCustomObjectTypeCode]
           ,[ExpireSubscriptionsInDays]
           ,[OrgDbOrgSettings]
           ,[PastExpansionWindow]
           ,[EnableSmartMatching]
           ,[MaxRecordsForLookupFilters]
           ,[BaseCurrencySymbol]
           ,[ReportScriptErrors]
           ,[RecurrenceExpansionJobBatchSize]
           ,[FutureExpansionWindow]
           ,[GetStartedPaneContentEnabled]
           ,[SampleDataImportId]
           ,[BaseISOCurrencyCode]
           ,[GoalRollupFrequency]
           ,[CreatedOnBehalfBy]
           ,[HashDeltaSubjectCount]
           ,[HashMaxCount]
           ,[FiscalYearFormatYear]
           ,[FiscalYearFormatPrefix]
           ,[PinpointLanguageCode]
           ,[FiscalYearFormatSuffix]
           ,[IsUserAccessAuditEnabled]
           ,[UserAccessAuditingInterval])
 SELECT
    @NewOrganizationId,
    [Name]
   ,[UserGroupId]
      ,[PrivilegeUserGroupId]
      ,[FiscalPeriodType]
      ,[FiscalCalendarStart]
      ,[DateFormatCode]
      ,[TimeFormatCode]
      ,[CurrencySymbol]
      ,[WeekStartDayCode]
      ,[DateSeparator]
      ,[FullNameConventionCode]
      ,[NegativeFormatCode]
      ,[NumberFormat]
      ,[IsDisabled]
      ,[DisabledReason]
      ,[KbPrefix]
      ,[CurrentKbNumber]
      ,[CasePrefix]
      ,[CurrentCaseNumber]
      ,[ContractPrefix]
      ,[CurrentContractNumber]
      ,[QuotePrefix]
      ,[CurrentQuoteNumber]
      ,[OrderPrefix]
      ,[CurrentOrderNumber]
      ,[InvoicePrefix]
      ,[CurrentInvoiceNumber]
      ,[UniqueSpecifierLength]
      ,[CreatedOn]
      ,[ModifiedOn]
      ,[FiscalYearFormat]
      ,[FiscalPeriodFormat]
      ,[FiscalYearPeriodConnect]
      ,[LanguageCode]
      ,[SortId]
      ,[DateFormatString]
      ,[TimeFormatString]
      ,[PricingDecimalPrecision]
      ,[ShowWeekNumber]
      ,[NextTrackingNumber]
      ,[TagMaxAggressiveCycles]
      ,[TokenKey]
      ,[SystemUserId]
      ,[CreatedBy]
      ,[GrantAccessToNetworkService]
      ,[AllowOutlookScheduledSyncs]
      ,[AllowMarketingEmailExecution]
      ,[SqlAccessGroupId]
      ,[CurrencyFormatCode]
      ,[FiscalSettingsUpdated]
      ,[ReportingGroupId]
      ,[TokenExpiry]
      ,[ShareToPreviousOwnerOnAssign]
      ,[AcknowledgementTemplateId]
      ,[ModifiedBy]
      ,[IntegrationUserId]
      ,[TrackingTokenIdBase]
      ,[BusinessClosureCalendarId]
      ,[AllowAutoUnsubscribeAcknowledgement]
      ,[AllowAutoUnsubscribe]
      ,[Picture]
      ,[TrackingPrefix]
      ,[MinOutlookSyncInterval]
      ,[BulkOperationPrefix]
      ,[AllowAutoResponseCreation]
      ,[MaximumTrackingNumber]
      ,[CampaignPrefix]
      ,[SqlAccessGroupName]
      ,[CurrentCampaignNumber]
      ,[FiscalYearDisplayCode]
      ,[SiteMapXml]
      ,[IsRegistered]
      ,[ReportingGroupName]
      ,[CurrentBulkOperationNumber]
      ,[SchemaNamePrefix]
      ,[IgnoreInternalEmail]
      ,[TagPollingPeriod]
      ,[TrackingTokenIdDigits]
      ,[NumberGroupFormat]
      ,[LongDateFormatCode]
      ,[UTCConversionTimeZoneCode]
      ,[TimeZoneRuleVersionNumber]
      ,[CurrentImportSequenceNumber]
      ,[ParsedTablePrefix]
      ,[V3CalloutConfigHash]
      ,[IsFiscalPeriodMonthBased]
      ,[LocaleId]
      ,[ParsedTableColumnPrefix]
      ,[SupportUserId]
      ,[AMDesignator]
      ,[CurrencyDisplayOption]
      ,[MinAddressBookSyncInterval]
      ,[IsDuplicateDetectionEnabledForOnlineCreateUpdate]
      ,[FeatureSet]
      ,[BlockedAttachments]
      ,[IsDuplicateDetectionEnabledForOfflineSync]
      ,[AllowOfflineScheduledSyncs]
      ,[AllowUnresolvedPartiesOnEmailSend]
      ,[TimeSeparator]
      ,[CurrentParsedTableNumber]
      ,[MinOfflineSyncInterval]
      ,[AllowWebExcelExport]
      ,[ReferenceSiteMapXml]
      ,[IsDuplicateDetectionEnabledForImport]
      ,[CalendarType]
      ,[SQMEnabled]
      ,[NegativeCurrencyFormatCode]
      ,[AllowAddressBookSyncs]
      ,[ISVIntegrationCode]
      ,[DecimalSymbol]
      ,[MaxUploadFileSize]
      ,[IsAppMode]
      ,[EnablePricingOnCreate]
      ,[IsSOPIntegrationEnabled]
      ,[PMDesignator]
      ,[CurrencyDecimalPrecision]
      ,[MaxAppointmentDurationDays]
      ,[EmailSendPollingPeriod]
      ,[RenderSecureIFrameForEmail]
      ,[NumberSeparator]
      ,[PrivReportingGroupId]
      ,[BaseCurrencyId]
      ,[MaxRecordsForExportToExcel]
      ,[PrivReportingGroupName]
      ,[YearStartWeekCode]
      ,[IsPresenceEnabled]
      ,[IsDuplicateDetectionEnabled]
      ,[RecurrenceExpansionJobBatchInterval]
      ,[DefaultRecurrenceEndRangeType]
      ,[HashMinAddressCount]
      ,[RequireApprovalForUserEmail]
      ,[RecurrenceDefaultNumberOfOccurrences]
      ,[ModifiedOnBehalfBy]
      ,[RequireApprovalForQueueEmail]
      ,[AllowEntityOnlyAudit]
      ,[IsAuditEnabled]
      ,[RecurrenceExpansionSynchCreateMax]
      ,[GoalRollupExpiryTime]
      ,[BaseCurrencyPrecision]
      ,[FiscalPeriodFormatPeriod]
      ,[AllowClientMessageBarAd]
      ,[InitialVersion]
      ,[HashFilterKeywords]
      ,[NextCustomObjectTypeCode]
      ,[ExpireSubscriptionsInDays]
      ,[OrgDbOrgSettings]
      ,[PastExpansionWindow]
      ,[EnableSmartMatching]
      ,[MaxRecordsForLookupFilters]
      ,[BaseCurrencySymbol]
      ,[ReportScriptErrors]
      ,[RecurrenceExpansionJobBatchSize]
      ,[FutureExpansionWindow]
      ,[GetStartedPaneContentEnabled]
      ,[SampleDataImportId]
      ,[BaseISOCurrencyCode]
      ,[GoalRollupFrequency]
      ,[CreatedOnBehalfBy]
      ,[HashDeltaSubjectCount]
      ,[HashMaxCount]
      ,[FiscalYearFormatYear]
      ,[FiscalYearFormatPrefix]
      ,[PinpointLanguageCode]
      ,[FiscalYearFormatSuffix]
      ,[IsUserAccessAuditEnabled]
      ,[UserAccessAuditingInterval]
  FROM
  [dbo].[OrganizationBase]
  WHERE
  OrganizationId = @OldOrganizationId
 
 -- Loop through the Found Columns and Update them with the new OrganizationId
 WHILE @ColumnIterator <= @ColumnTotal
  BEGIN
   DECLARE @CurrentTable nvarchar(max)
   DECLARE @CurrentColumn nvarchar(max)
  
   SET @CurrentTable = (SELECT TableName FROM @FoundOrganizationIds WHERE Id = @ColumnIterator)
   SET @CurrentColumn = (SELECT ColumnName FROM @FoundOrganizationIds WHERE Id = @ColumnIterator)
  
   --PRINT (@CurrentTable)
   --PRINT (@CurrentColumn)
  
   -- Skip the OrganizationBase table now, since we have allready added the new OrganizationId
   IF @CurrentTable <> 'OrganizationBase'
    BEGIN
     DECLARE @UpdateScript nvarchar(max)
     SET @UpdateScript = ' UPDATE ' + @CurrentTable + ' SET ' + @CurrentColumn + ' = ' + CHAR(39) + CAST(@NewOrganizationId as varchar(50)) + CHAR(39) + ' WHERE ' + @CurrentColumn + ' = ' + CHAR(39) + CAST(@OldOrganizationId as varchar(50))+ CHAR(39)
     -- PRINT (@UpdateScript)
     EXEC (@UpdateScript)
    END
   SET @ColumnIterator = @ColumnIterator + 1
  END

 -- Delete the Old Organization from the OrganizationBase
 DELETE FROM OrganizationBase WHERE OrganizationId = @OldOrganizationId

Wednesday, July 29, 2015

Actions in CRM2013/15

  • Navigate to Settings->Process->New.
  • Use following details and click on OK :
    1. Process name: ActionDemo
    2. Category: Action
    3. Entity: None(global)
    4. Type: New blank process
  • Add a Input parameter of Entity type for ParentAccount record like below:
entityparameter
  • Add another input parameter of type EntityReference to get Salesperson
salesperson
Now let’s say we want to use these parameters to create our contact record, so follow below steps to create contact record using these parameters:
  • Click on Add Step and select Create Record step under drop down
contacreate
  • Select Contact under Create drop down like below and click on Set Properties.
  • Now we will be using our Entity object input parameter to fetching different property and will be setting in contact record
  • Select the field that you want to set, for example we want to set Account Name, so click on Account Name field and click on OK after setting following options from Form Assistant like below:
Assitent
  • Similar we can select other fields like Email, Mobile, Firstname, Last name from account entity object like belowcotnact
  • Now select the Sales person field and select out second parameter from Form assistant like below (Note: We have created a custom lookup for Sales Person field in Contact entity) and click on Save and Close
salesperson

Now we need to activate our action and we can call it using server side code, client side code and using other Workflow and dialogs as well (new feature in CRM 2015). We ca use following code call our action:
//we have written method to get CRM service object
IOrganizationService service = connection.GetCRMService();
//retrieve account record using that we want to create contact
Entity accountObj = service.Retrieve(“account”, new Guid(“699D9F32-9B10-E511-80FD-C4346BAD3138″), new ColumnSet(true));

//Create organization Request object and pass action name as parameter
OrganizationRequest Req = new OrganizationRequest(“new_actiondemo”);
Req[“ParentAccount”] = accountObj; //passing our first parameter
Req[“Salesperson”] = new EntityReference(“systemuser”, new Guid(“90322292-C8EC-4A72-8B32-B79DEF7DD31C”));
//use execute method to call action
OrganizationResponse Respons = service.Execute(Req);

After execution of the code we can see in CRM contact record is created by action like below:
resultaction
So in above example we show if we need to pass multiple parameter we can use Entity object instead of passing field value one by one and entity reference is used to for passing a single entity reference instance.

Tuesday, July 28, 2015

Create, Update , Delete Record using Javascript in CRM2011/13/15 using Soap Query

Soap Query to Create/Update/Delete using Javascript in CRM2011/13/15

Creating Contact entity record

// Prepare values for the new contact.
var firstname = "Navish";
var lastname = "Jain";
var donotbulkemail = "true";
var address1_stateorprovince = "CHD";
var address1_postalcode = "160036";
var address1_line1 = "#1429/2";
var address1_city = "Chandigarh";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='contact'>" +
"<address1_city>" + address1_city + "</address1_city>" +
"<address1_line1>" + address1_line1 + "</address1_line1>" +
"<address1_postalcode>" + address1_postalcode + "</address1_postalcode>" +
"<address1_stateorprovince>" + address1_stateorprovince + "</address1_stateorprovince>" +
"<donotbulkemail>" + donotbulkemail + "</donotbulkemail>" +
"<firstname>" + firstname + "</firstname>" +
"<lastname>" + lastname + "</lastname>" +
"</entity>" +
"</Create>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// 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;
    alert(msg);
}

XML with a CreateResponse element that returns the ID for the record created


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <CreateResponse xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
   <CreateResult>368c8b1b-851c-dd11-ad3a-0003ff9ee217</CreateResult>
  </CreateResponse>
 </soap:Body>
</soap:Envelope>




Updating Contact Record

// Prepare variables for updating a contact.
var contactId = "89a7e456-8098-bb33-b345-0003gg9ff218";
var newAddressLine1 = "#1429/2";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='contact'>" +
"<address1_line1>" + newAddressLine1 + "</address1_line1>" +
"<contactid>" + contactId + "</contactid>" +
"</entity>" +
"</Update>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Update");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// 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;
    alert(msg);
}

XML that returns a UpdateResponse


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <UpdateResponse xmlns="http://schemas.microsoft.com/crm/2007/WebServices" />
 </soap:Body>
</soap:Envelope>


Deleting Contact record

// Identify the contact to delete.
var contactid = "89a7e456-8098-bb33-b345-0003gg9ff218";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
authenticationHeader+
"<soap:Body>"+
"<Delete xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entityName>contact</entityName>"+
"<id>"+contactid+"</id>"+
"</Delete>"+
"</soap:Body>"+
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request,
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Delete");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// 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;
 alert(msg);
}

XML that returns a DeleteResponse


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <DeleteResponse xmlns="http://schemas.microsoft.com/crm/2007/WebServices" />
 </soap:Body>
</soap:Envelope>

Monday, July 27, 2015

Assign Team Using Create/Update Operation

Hi Team,

Please Use Below Code to Assign Team using Create/Update operation in Plugins

//Assign a record to a team
 private void AssignRecord(Entity TargetEntity, Guid TargetRecordID, Guid OwningTeamID, IOrganizationService orgService)
 {
     try
     {
         // Create the Request Object and Set the Request Object's Properties
         AssignRequest assign = new AssignRequest
         {
             Assignee = new EntityReference("team", OwningTeamID),
             Target = new EntityReference(TargetEntity.LogicalName, TargetRecordID)
         };
 
         // Execute the Request
         orgService.Execute(assign);
     }
     catch (Exception ex)
     {
         throw new Exception("An error occured while assinging Team to a record." + ex.Message);
     }
 }

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...