Extend/Change Recalculate Order button results

Unanswered Extend/Change Recalculate Order button results

  • Saturday, January 26, 2013 11:35 AM
     
     

    Hi there,

    I'm looking at changing the Order Recalculate function because I added some fields both in the "Salesorder" Entity and "Salesorderdetail" Entity.

    I've been investigating and debugging this and as far as I can tell:

    1. The order calculation is not done in Javascript but in code, when I debug in the pre-processing step I do not see the calculated values in the attributes
    2. If I do some recalculation and set the result fields myself, CRM overwrites my results. I tried this in pre-validation, pre-processing and post-processing with service.Update function.

    Can someone tell me how I can get this working and where I'm missing something? I've been stuck with this since a few days and any help would be welcome.

All Replies

  • Saturday, January 26, 2013 1:23 PM
     
     

    hi,

    do you need to override ReCalculate system functionality to your functionality..?


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

  • Saturday, January 26, 2013 6:39 PM
     
     
    yes, I included extra discount fields that need to be included in the calculation
  • Saturday, January 26, 2013 7:05 PM
     
     

    Hi,

    Please check the following post

    http://aadreja.wordpress.com/2009/07/13/override-price-opportunity-product-mscrm-4-0/

    Or you could create custom fields (Extended Amount, Net Amount etc.) and write plugin on Create/Update messages to override your calculations accordingly.


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

  • Sunday, January 27, 2013 11:12 AM
     
     

    Hi _Vikram,

    I don't want to mess with the database and I'm looking for a solution through CRM so the first link you gave me isn't a good solution for me.  Secondly I already tried using a plugin with Create/Update messages in pre-validation, pre-operation and post-operation phases but doesn't seem to work.  My custom fields are calculated correctly but the CRM result fields are overridden with the CRM calculated results.

    Any ideas what I'm doing wrong or if it should work like this?

  • Monday, January 28, 2013 9:24 AM
     
     

    Hi _Vikram,

    Can you explain more about how I should create the custom plugin? (see my previous post)

  • Monday, February 18, 2013 9:43 AM
     
     
    Still couldn't find this one, anyone with more help?
  • Monday, February 18, 2013 12:11 PM
     
     
    Add a new button having same image as recalculate and put your logic behind it. Hide the existing button.

    Regards Faisal

  • Tuesday, February 19, 2013 7:54 AM
     
     

    That won't help I suppose since my recalculation is done when saving the record and still overwritten.

    Is there a blog post or similar that explains how this recalculation exactly works?

  • Tuesday, February 19, 2013 12:05 PM
     
      Has Code

    You can add/remove you own function on save

    function addMessageToOnSave() {
     Xrm.Page.data.entity.addOnSave(displayMessage);
    }
    function displayMessage() {
     alert("message");
    }

    For details follows this link:-

    http://msdn.microsoft.com/en-gb/library/gg334720.aspx#BKMK_addOnSave


    Regards Faisal

  • Tuesday, February 19, 2013 12:29 PM
    Answerer
     
     
    There are solutions such as Visual Ribbon Editor, which could be used to edit the ribbon buttons. But, even these solutions could not customize the built-in ribbon buttons. You could create your own button as Faisal said, and then hide the main button. Then on the click of the new recalculate button you could do your own calculations plus triggering the main recalculate button.

    If the answer helped you, remember to mark it as answer.

  • Wednesday, February 20, 2013 8:42 AM
     
     

    Hi,

    Better try a simple Plugin with the logic you need and call that plugin under the create of Order entity. You will be resolved.

    In this plugin, I have added some custom fields in Quote product entity and calculated the totals,once a Quote product with that field is created for that Quote. Try similar plugin like this:

    public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)
                   serviceProvider.GetService(typeof(IPluginExecutionContext));

                // The InputParameters collection contains all the data passed in the message request.
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                {

                    Entity entity = (Entity)context.InputParameters["Target"];

                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                    {
                        if (entity.LogicalName == "quotedetail")
                        {

                            EntityReference QuoteId = entity.GetAttributeValue<EntityReference>("new_quote"); //Quote Lookup Field in Quote Product Entity
                            Entity Quote = service.Retrieve(QuoteId.LogicalName, QuoteId.Id, new ColumnSet("new_amount", "new_totalcost")); //Fields in Quote Entity

                            Quote.Attributes["new_amount"] = entity.GetAttributeValue<int>("new_totalcost");
                            Quote.Attributes["new_totalcost"] = ((int)Quote.Attributes[new_amount"]) + ((int)Quote.Attributes["new_totalcost"]);

                            service.Update(Quote);
                        }
                    }
                }
            }


    Naren


    • Edited by Naren prp Wednesday, February 20, 2013 8:47 AM
    •  
  • Wednesday, February 20, 2013 9:06 AM
     
     

    Hi Naren prp,

    Did you get this to work?

    I created a plugin and registered it for "Update" on the "salesorder" entity. In this plugin I've done the calculation as I would like to have it, but when saving the order CRM still overwrites my calculated values with the CRM calculated values. I know this for sure because my custom fields contain the values, only the CRM fields contain incorrect values.

  • Wednesday, February 20, 2013 5:59 PM
     
     

    I found that the issue is not recalculating, but infinites loop.

    I'll create a new topic for that.