locked
MS CRM 2011 - Order's total tax field RRS feed

  • Question

  • Is there a way to modify total tax field in order form by myself. With code

    var totalamount = Xrm.Page.getAttribute('totallineitemamount').getValue();
    		var totalvat = 0.24 * totalamount;
    	Xrm.Page.getAttribute('totaltax').setValue(totalvat); 

    I want to take Total detail amount and multiply it by 0.24 and save the result to the total tax field.

    With that code the calculation works, then the result goes to the total tax field so I can see that the formula works, but finaly the total tax field becomes empty.

    The code is triggered by recalculate button.

    Thursday, July 18, 2013 6:33 AM

Answers

  • CRM don't take tax value from product. An earlier code or workflow or plugin might be doing this. See what code is running onLoad of form. If it is related to tax than disable it and test.

    Regards Faisal

    Hi everybody,

    CRM definitely takes the total tax of quotes, orders and invoices from their products. When you set the tax value on the product of these entities, then on the calculation of all of these entities it sums up the tax of all of the products of the entity. This is why you could not set the tax by the JavaScripts. With whatever function or button you do this, ultimately, when you click on the calculate button it sets back the total tax as the sum of the products tax. You may have three solutions:

    1- Change the mechanism of the recalculate button to not set the total tax from the products. Very unsupported and harmful! I do not suggest this one. But if you insist on your idea you could do this.

    2- Create an OnSave and OnChange JavaScript function to set the tax on the products. This method has some issues. For example, when you want to set the tax as 0.24 of the total amount, the total amount is empty on the create of the form. Hence, you should retrieve the quantity, price per unit and other values and manually calculate the total amount and then the tax. This is not a complete solution, however, could resolve your issue.

    3- Use a plugin on the create and update of the quote products (order product or invoice product). Then, you could easily update the  tax value without any of the mentioned difficulties in the section 2.



    My Weblog | My Website

    Thursday, July 18, 2013 9:57 AM
    Moderator

All replies

  • Put this line at the end of your code:-

    Xrm.Page.getAttribute("totaltax").setSubmitMode("always");


    Regards Faisal

    Thursday, July 18, 2013 7:11 AM
  • Put this line at the end of your code:-

    Xrm.Page.getAttribute("totaltax").setSubmitMode("always");


    Regards Faisal

    Nope, that doesn't work either. It causes the same situation. First the value comes correctly, but when the form reloads, the field is empty.

    I think the problem is that CRM takes total tax value from products somewhere. Now when the form loads, it takes tax values which are empty and put those empty values to the total tax field.

    Thursday, July 18, 2013 7:57 AM
  • CRM don't take tax value from product. An earlier code or workflow or plugin might be doing this. See what code is running onLoad of form. If it is related to tax than disable it and test.

    Regards Faisal

    Thursday, July 18, 2013 8:30 AM
  • Do like this

    Xrm.Page.getAttribute("totaltax").setSubmitMode("always");

    var totalamount = Xrm.Page.getAttribute('totallineitemamount').getValue();
    		var totalvat = 0.24 * totalamount;
    	Xrm.Page.getAttribute('totaltax').setValue(totalvat); 

    Xrm.Page.Data.entity.save();

    Thursday, July 18, 2013 8:33 AM
  • CRM don't take tax value from product. An earlier code or workflow or plugin might be doing this. See what code is running onLoad of form. If it is related to tax than disable it and test.

    Regards Faisal

    Yes well, order take it from order product. There is also no code in onLoad, no plugin or no workflow.
    Thursday, July 18, 2013 9:12 AM
  • Do like this

    Xrm.Page.getAttribute("totaltax").setSubmitMode("always");

    var totalamount = Xrm.Page.getAttribute('totallineitemamount').getValue();
    		var totalvat = 0.24 * totalamount;
    	Xrm.Page.getAttribute('totaltax').setValue(totalvat); 

    Xrm.Page.Data.entity.save();


    I am using code:
    function Tax(prmContext) {
        // Local variable to store value indicating how the save event was initiated by the user.
        var wod_SaveMode, wod_SaveEventVal;
    		var vat = Xrm.Page.getAttribute('new_vat').getValue();
    
        // Change the Save Event Value as per required Save Event
        wod_SaveEventVal = 1;
    
        if (prmContext != null && prmContext.getEventArgs() != null) {
    
            wod_SaveMode = prmContext.getEventArgs().getSaveMode();
    
            // 1 will pass on Recalculate button click
            if (wod_SaveMode == wod_SaveEventVal) {
             
    		 alert(+wod_SaveMode);
    		alert("calcutale tax");
    		
    
    		
    		if (vat == 100000000) {
    		alert("vat 24");
    		var totalamount = Xrm.Page.getAttribute('totallineitemamount').getValue();
    		var totalvat = 0.24 * totalamount;
    		
    		Xrm.Page.getAttribute('totaltax').setSubmitMode("always");
    		Xrm.Page.getAttribute('totaltax').setValue(totalvat); 
    		//Xrm.Page.data.entity.save();
    		
    		}
    		
    
     
    
    
    
                // Use the code line below only if validation is failed then abort function save event
              //  prmContext.getEventArgs().preventDefault();
    
            }
        }
    }
    If I don't comment the line Xrm.Page.Data.entity.save(); out, the crm loops over and over again. The calculation must be done when user pushes recalculate button. The code above is in onSave event.
    Thursday, July 18, 2013 9:54 AM
  • CRM don't take tax value from product. An earlier code or workflow or plugin might be doing this. See what code is running onLoad of form. If it is related to tax than disable it and test.

    Regards Faisal

    Hi everybody,

    CRM definitely takes the total tax of quotes, orders and invoices from their products. When you set the tax value on the product of these entities, then on the calculation of all of these entities it sums up the tax of all of the products of the entity. This is why you could not set the tax by the JavaScripts. With whatever function or button you do this, ultimately, when you click on the calculate button it sets back the total tax as the sum of the products tax. You may have three solutions:

    1- Change the mechanism of the recalculate button to not set the total tax from the products. Very unsupported and harmful! I do not suggest this one. But if you insist on your idea you could do this.

    2- Create an OnSave and OnChange JavaScript function to set the tax on the products. This method has some issues. For example, when you want to set the tax as 0.24 of the total amount, the total amount is empty on the create of the form. Hence, you should retrieve the quantity, price per unit and other values and manually calculate the total amount and then the tax. This is not a complete solution, however, could resolve your issue.

    3- Use a plugin on the create and update of the quote products (order product or invoice product). Then, you could easily update the  tax value without any of the mentioned difficulties in the section 2.



    My Weblog | My Website

    Thursday, July 18, 2013 9:57 AM
    Moderator
  • CRM don't take tax value from product. An earlier code or workflow or plugin might be doing this. See what code is running onLoad of form. If it is related to tax than disable it and test.


    Regards Faisal

    Hi everybody,

    CRM definitely takes the total tax of quotes, orders and invoices from their products. When you set the tax value on the product of these entities, then on the calculation of all of these entities it sums up the tax of all of the products of the entity. This is why you could not set the tax by the JavaScripts. With whatever function or button you do this, ultimately, when you click on the calculate button it sets back the total tax as the sum of the products tax. You may have three solutions:

    1- Change the mechanism of the recalculate button to not set the total tax from the products. Very unsupported and harmful! I do not suggest this one. But if you insist on your idea you could do this.

    2- Create an OnSave and OnChange JavaScript function to set the tax on the products. This method has some issues. For example, when you want to set the tax as 0.24 of the total amount, the total amount is empty on the create of the form. Hence, you should retrieve the quantity, price per unit and other values and manually calculate the total amount and then the tax. This is not a complete solution, however, could resolve your issue.

    3- Use a plugin on the create and update of the quote products (order product or invoice product). Then, you could easily update the  tax value without any of the mentioned difficulties in the section 2.



    My Weblog | My Website

    Hi

    Yes you are right with your thoughts of taxes. I have to think about the problem again. But probably the best way is calculate the tax in somewhere product form or product order form. But not in the order form.

    Thursday, July 18, 2013 10:13 AM
  • Use this addon to add vat calculation to invoice, quote and sales order: http://bit.ly/1P5MsMD
    • Proposed as answer by Stephan Thurek Friday, February 5, 2016 8:49 AM
    Friday, February 5, 2016 8:49 AM