0

Below is my Product sub grid on Quote Entity.

Now On addition of new product , I am calculating Service tax and tax based on Price per unit, quantity and discount.

Now i need to set calculated service tax and tax value in sub grid.

enter image description here

I want to Update record of a Sub-grid in Quote Entity. I have tried below code, but still not able to update my sub grid .

function OnRefresh()
{ 
    var gridControl = document.getElementById("quotedetailsGrid").control;
    var  ids = gridControl.get_allRecordIds();  

    for (i = 0; i < ids.length; i++) {

      var quotedetail = new Object(); 
      quotedetail.new_service_tax = "1000";                 

      var id = ids[i].replace("{", "").replace("}", "");                                        

      QuoteProductRecord(id,quotedetail);

    }
}


function QuoteProductRecord(id,quotedetail) {

var jsonEntity = window.JSON.stringify(quotedetail);

var ODataPath = Xrm.Page.context.getServerUrl() + "/XrmServices/2011/OrganizationData.svc/QuoteDetailSet";

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    data: jsonEntity,
    url: ODataPath + "(guid'" + id + "')",
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
        XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
    },
    success: function (data, textStatus, XmlHttpRequest) {

       alert("Success");
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) { }
});

}

Issue is that there is no error thrown, but still Service tax and tax value in sub grid is blank.

In JSON function, i have also tried to alert success message , but neither i got any success message nor any error message.

User5590
  • 1,383
  • 6
  • 26
  • 61
  • Just curious, why would you want to use javascript to update the values? Is there a reason you don't use a pre-/post-create plugin? – Thijs Kuipers Apr 15 '14 at 09:55

2 Answers2

0

Check if the operations that you are doing are legit. Is it possible that you are passing a value that results in an empty string.

Mauro De Biasio
  • 1,146
  • 6
  • 16
0

I have just import my solution with above code in my production environment (CRM2013 Online). and it worked fine.

User5590
  • 1,383
  • 6
  • 26
  • 61