Hi All,
I am using Editable Crm Grid in which my requirement is, on change of product unit, the unit value should appear in field.
i wrote following script.
function setPricePerUnitbase() {
var productId = null;
var Uomid = null;
var CurrencyId = null;
var editedrow = AbleBridge.DataGrid.GetEditRows()[0].RowIndex;
var rowIndex = AbleBridge.DataGrid.GetRowData()[editedrow];
var isfound = false;
try { productId = rowIndex.ProductId.Id } catch (ex) { productId = null; }
try { CurrencyId = rowIndex.TransactionCurrencyId.Id ; } catch (ex) { TransactionCurrencyId = null; }
try { Uomid = rowIndex.UoMId.Id; } catch (ex) { Uomid = null; }
//If existing product is selected then set productId to the GUID of existing product.
debugger;
if (productId !== null && Uomid != null) {
var req = new XMLHttpRequest();
var url = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ProductSet(guid'" + productId + "')?$select=product_price_levels/Amount,product_price_levels/TransactionCurrencyId,product_price_levels/UoMId&$expand=transactioncurrency_product,product_price_levels&$filter=transactioncurrency_product/ TransactionCurrencyId ne null ";
req.open("GET", url, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (req.readyState == 4) {
var data = JSON.parse(req.responseText);
var values = new Array();
values = data.d.product_price_levels.results;
debugger;
values.forEach(function (item, index) {
if (item.TransactionCurrencyId.Id == CurrencyId && item.UoMId.Id == Uomid) {
AbleBridge.DataGrid.SetFieldValue('PricePerUnit', item.Amount.Value, rowIndex);
isfound = true;
}
})
if (isfound == false) {
alert("The Unit Price Does Not Exist for this unit");
AbleBridge.DataGrid.SetFieldValue('PricePerUnit', null, rowIndex);
}
}
};
req.send(null);
}
};
the issue is, after changing the product unit from column, the row index is pulling same old record unit, not the new one which i selected. The same script works when i add new product, with rowindex as insert NewrowIndex