Posts

Showing posts from February, 2015

How to update the Parent data when child record is created/Updated/Deleted

function DisplayTotal() {  if (Xrm.Page.ui.getFormType() == 2)   {  var OpportunityId = Xrm.Page.data.entity.getId();  var Total=0;     if (OpportunityId != null)  {         var Opportunity = GetTotalLineItemValue(OpportunityId);   if (Opportunity != null && Opportunity.length>0 && Opportunity[0].results != null && Opportunity[0].results.length>0)    { for (var count = 0; count < Opportunity[0].results.length; count++) { // alert(Opportunity[0].results[count].ExtendedAmount.Value); Total= parseFloat(Total) + parseFloat(Opportunity[0].results[count].ExtendedAmount.Value);           //alert(Opportunity[0].results[count].LastName);   }   Xrm.Page.getAttribute("new_totalmyamt").setValue(Total);   }   }   } } function GetTotalLineItemValue(OpportunityId) {     var serverUrl = Xrm.Page.context.getServerUrl();      var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/OpportunityProductSe
How to Return Multiple Value from method ====================================================================         private static decimal[] FetchResult(Guid OpportunityID, IOrganizationService service)         {             Entity postImageEntity = new Entity();             string FetchOpportunityProduct = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>                         <entity name='opportunityproduct'>                                                <attribute name='ti_extendedenhancement' alias='totalservicecostamount_sum' aggregate='sum' />                                 <attribute name='ti_extendedserviceamount' alias='totalamount_sum' aggregate='sum'/>                                                 <link-entity name='opportunity' from='opportu
Plugin Trigger ·      Create or Update of Quote Product record Plugin logic When a Quote Product record is created or updated, override the default price with the following formula. Formula: IF(Discount is null, ProductPrice, ProductPrice – (ProductPrice*(Discount/100))) ProductPrice = PriceListItem.Amount Discount = Account.sts_discount Set ispriceoverridden to 1 and populate the amount field with the formula above Code: using System; using System.ServiceModel; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm; using Microsoft.Xrm.Sdk.Query; namespace Car_O_Liner_QuoteDiscount {     public class QuoteDiscount : IPlugin     {         public void Execute(IServiceProvider serviceProvider)         {             IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));             IOrganizationServiceFactory serviceFa
Auto-copy field on save/recalculate.   #region References using System; using System.ServiceModel; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm; using Microsoft.Xrm.Sdk.Query; #endregion namespace AutoCopyOpportunityQuote {     public class AutoCopytoQuote:IPlugin     {         public void Execute(IServiceProvider serviceProvider)         {             IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));             IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));             IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);             ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));             Guid OpportunityID = Guid.Empty;             t
How to update the parent record when child record is created/updated/Delete The scenario is that I want to display the sum of total of “Service Cost” of the opportunity Product on the parent opportunity record. #region References using System; using System.ServiceModel; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm; using Microsoft.Xrm.Sdk.Query; #endregion namespace OpportunityCost {     public class OpportunityCost : IPlugin     {         public void Execute(IServiceProvider serviceProvider)         {             IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));             IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));             IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);