Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Use Javascript to Update Price Per Unit When Selecting a Product in Dynamics CRM 2011

$
0
0

PowerObjects - Use Javascript to Update Price Per Unit When Selecting a Product in Dynamics CRM 2011

Attempting to use this jscript below, getting the following error when debugging...Any help would be appreciated. Thanks

"Unable to get value of the property '0': object is null or undefined"

Line 39

"Unterminated string constant"

Line 8

function onChangeUnit() {

var productField = Xrm.Page.getAttribute("productid").getValue();

var productFieldId = productField[0].I\id;

//store the product guid here

if (productFieldId != null) //if product not null get guid for unit
{
var unit = Xrm.Page.getAttribute("uomid").getValue();

//get guid for Parent opportunity

var opportunityId = Xrm.Page.getAttribute("opportunityid").getValue();

if (opportunityId != null)

//if opportunity guid is null, discontinue

{
//build query

var pagecontext = Xrm.Page.context;

var serverUrl = pagecontext.getServerUrl();

var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

var oDataSelect = oDataPath + "OpportunitySet?$select=PriceLevelId&$filter=OpportunityId eq guid'" + opportunityId + "'";

//start AJAX call for the parent price list guid

$.ajax({

type: "GET",

contentType: "application/json;charset=utf-8",

datatype: "json",

url: oDataSelect,

beforeSend: function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},

success: function (data, status)
{
NowWeHaveThePriceList(data, status, productFieldId, unit, oDataPath);
},

error: function (XmlHttpRequest, textStatus, errorThrown)
{
alert("OData Select Failed : " + errorThrown + " .There is no parent price list ");

}

});

}

}

}

function NowWeHaveThePriceList(data, status, productFieldId, unit, oDataPath)
{
var priceLevelId = data.d.results[0].PriceLevelId.Id; //retrieved pricelevel

//start AJAX clal for Price List Item entities = Price List GUID and Product Guid and Unit Guid and return the Amount on that price list item. This will return one results.

var oDataSelect2 = oDataPath + "ProductPriceLevelSet?$select=Amount&$filter=PriceLevelId/Id eq guid'" + priceLevelId + "' and ProductId/Id eq guid'" + productFieldId + "' and UoMId/Id eq guid'" + unit[0].id + "'";

$.ajax({

type: "GET",

contentType: "application/json;charset=utf-8",

datatype: "json",

url: oDataSelect2,

beforeSend: function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},

success: NowWeHavePrice,
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert("OData Select Failed : " + errorThrown + " .There is no price list item for this product");

}

});

}

function NowWeHavePrice(data, status)
{
if (data != null) {

//set the price per unit

var priceListItemAmount = data.d.results[0].Amount.Value;

Xrm.Page.getAttribute("priceperunit").setValue(parseFloat(eval(priceListItemAmount)));

Xrm.Page.getAttribute("priceperunit").setSubmitModeAlways;

}
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>