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

  • Question

  • 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;

    }
    }

    Tuesday, April 30, 2013 5:49 PM

Answers

  • There were 2 instances where you had ’ and not a '

    Be careful when cutting and pasting code from the web - sometimes the single and double quotes get messed up (I think they call them "Smart Quotes") - JavaScript doesn't like them :)

    function updateProductPrice() {
    
        //Developed by PowerObjects 11/9/2012
        //This jscript is intended to fire off on the OnChange event of the Product lookup on Opportunity Products
        //Once user inputs a product, the default unit for the product will set, and price per unit, from the Price List Item, will populate below
        //This javascript assumes there are price lists.
    
        var productField = Xrm.Page.getAttribute('productid').getValue();
        var productFieldId = productField[0].id;
        if (productFieldId != null) {
    
            //build the query to get the default unit
    
            var pagecontext = Xrm.Page.context;
            var serverUrl = pagecontext.getServerUrl();
            var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
            var oDataSelect = oDataPath + "ProductSet?$select=DefaultUoMId&$filter=ProductId eq guid'" + productFieldId + "'";
    
            //alert(oDataSelect );
    
            //Start AJAX call to get default unit guid from product
    
            $.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) {
                    NowHaveDefaultUnitGuid(data, status, productFieldId, oDataPath);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert("OData Select Failed: " + errorThrown + ". There is no default unit associated with product");
                }
            });
        }
    }
    
    function NowHaveDefaultUnitGuid(data, status, productFieldId, oDataPath) {
    
        //we are passing the oDataPath and productFieldId since we will still need these variables
    
        var defaultUnitGUID = data.d.results[0].DefaultUoMId; //retrieved defaultUnit guid
        var opportunityId = Xrm.Page.getAttribute('opportunityid').getValue();
        if (opportunityId != null) {
            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) {
                    NowWeHaveEverything(data, status, productFieldId, defaultUnitGUID, oDataPath);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert('OData Select Failed: ' + errorThrown + ". There is no parent price list");
                }
            });
        }
    }
    
    function NowWeHaveEverything(data, status, productFieldId, defaultUnitGUID, oDataPath) {
    
        //now that we have the pricelist guid, default unit guid, we can lookup the price list item to pull the amount value
    
        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'" + defaultUnitGUID.Id + "')";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataSelect2,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, status) {
                havePrice(data, defaultUnitGUID);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert('OData Select Failed: ' + errorThrown + ". There is no price list item for this product");
            }
        });
    }
    
    function havePrice(data, defaultUnitGUID) {
        if (defaultUnitGUID != 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;
            //set the unit on Opportunity below.
            var id = defaultUnitGUID.id;
            var name = defaultUnitGUID.Name.toString();
            var entityType = defaultUnitGUID.LogicalName.toString();
            Xrm.Page.getAttribute("uomid").setValue([{
                    id: id,
                    name: name,
                    entityType: entityType
                }
            ]);
        }
    }

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, May 1, 2013 5:53 PM
    Moderator

All replies

  • Try this - I think you just had a typo on this line

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

    function onChangeUnit() {
        var productField = Xrm.Page.getAttribute("productid").getValue();
        var productFieldId = productField[0].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;
        }
    }


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, May 1, 2013 1:42 PM
    Moderator
  • And don't forget to use the code block tool when posting code :)


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, May 1, 2013 1:46 PM
    Moderator
  • Thanks Jason, I did notice that yesterday and made the change..now I am close but having issues with the pulling the default unit. I was getting errors with  'unit[0].id' so I made some changes.

    Currently the price per unit does work, however only when I take out the bold.

    function onChangeUnit()

    {
     
    var productField = Xrm.Page.getAttribute('productid').getValue();
     
    var productFieldId = productField[0].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'" + defaultUnitGUID.Id  + "'";

    var oDataSelect2 = oDataPath + "ProductPriceLevelSet?$select=Amount&$filter=PriceLevelId/Id eq guid'" + priceLevelId + "' and ProductId/Id eq guid'" + productFieldId + "' and Uomid/Id eq guid'" + defaultUnitGUID.Id  +"'";

    //window.alert(defaultUnitGUID.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, defaultUnitGUID)
     {
     if (defaultUnitGUID != 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;

    var id = defaultUnitGUID.Id;

    var name = defaultUnitGUID.Name.toString();

    Xrm.Page.getAttribute("uomid").setValue( [{id: id, name: name, entityType: entityType}]);

     

    }

     }

    Wednesday, May 1, 2013 1:48 PM
  • I'm a bit unclear what you are trying to do with the unit of measure at the end? Isn't this already set (assuming this all kicks off after the user picks the product then UOM).

    You would have problems with 'defaultUnitGUID' as you've never assigned a value to it.


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, May 1, 2013 2:34 PM
    Moderator
  • Sorry.

    This is the code from power objects, having trouble getting the default guid from the product, the alert is working. I double checked and I do have default units for all products.

    function updateProductPrice(){
    
     //Developed by PowerObjects 11/9/2012
     //This jscript is intended to fire off on the OnChange event of the Product lookup on Opportunity Products
     //Once user inputs a product, the default unit for the product will set, and price per unit, from the Price List Item, will populate below
     //This javascript assumes there are price lists.
    
     var productField = Xrm.Page.getAttribute('productid').getValue();
     var productFieldId = productField[0].id;
     if (productFieldId != null){
    
     //build the query to get the default unit
    
     var pagecontext = Xrm.Page.context;
     var serverUrl = pagecontext.getServerUrl();
     var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
     var oDataSelect = oDataPath + "ProductSet?$select=DefaultUoMId&$filter=ProductId eq guid’" + productFieldId + "'";
    
    //alert(oDataSelect );
    
     //Start AJAX call to get default unit guid from product
    
     $.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) { NowHaveDefaultUnitGuid(data,status,productFieldId,oDataPath);},
     error: function (XmlHttpRequest, textStatus, errorThrown) {
     alert("OData Select Failed: " + errorThrown + ". There is no default unit associated with product");
     }
     });
     }
     }
     function NowHaveDefaultUnitGuid(data, status, productFieldId, oDataPath) {
    
     //we are passing the oDataPath and productFieldId since we will still need these variables
    
     var defaultUnitGUID = data.d.results[0].DefaultUoMId;//retrieved defaultUnit guid
     var opportunityId = Xrm.Page.getAttribute('opportunityid').getValue();
     if (opportunityId != null)
     {
     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) { NowWeHaveEverything(data,status,productFieldId,defaultUnitGUID,oDataPath);},
     error: function (XmlHttpRequest, textStatus, errorThrown) {
     alert('OData Select Failed: ' + errorThrown + ". There is no parent price list");
     }
     });
     }
     }
     function NowWeHaveEverything(data, status, productFieldId,defaultUnitGUID, oDataPath) {
    
     //now that we have the pricelist guid, default unit guid, we can lookup the price list item to pull the amount value
    
     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'" + defaultUnitGUID.Id + "')";
     $.ajax({
     type: "GET",
     contentType: "application/json; charset=utf-8",
     datatype: "json",
     url: oDataSelect2,
     beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
     success: function (data,status){ havePrice(data, defaultUnitGUID);},
     error: function (XmlHttpRequest, textStatus, errorThrown) {
     alert('OData Select Failed: '+ errorThrown + ". There is no price list item for this product");
     }
     });
     }
     function havePrice(data, defaultUnitGUID){
     if(defaultUnitGUID != 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;
     //set the unit on Opportunity below.
     var id = defaultUnitGUID.id;
     var name = defaultUnitGUID.Name.toString();
     var entityType = defaultUnitGUID.LogicalName.toString();
     Xrm.Page.getAttribute("uomid").setValue( [{id: id, name: name, entityType: entityType}]);
     }
     }

    Wednesday, May 1, 2013 3:29 PM
  • There were 2 instances where you had ’ and not a '

    Be careful when cutting and pasting code from the web - sometimes the single and double quotes get messed up (I think they call them "Smart Quotes") - JavaScript doesn't like them :)

    function updateProductPrice() {
    
        //Developed by PowerObjects 11/9/2012
        //This jscript is intended to fire off on the OnChange event of the Product lookup on Opportunity Products
        //Once user inputs a product, the default unit for the product will set, and price per unit, from the Price List Item, will populate below
        //This javascript assumes there are price lists.
    
        var productField = Xrm.Page.getAttribute('productid').getValue();
        var productFieldId = productField[0].id;
        if (productFieldId != null) {
    
            //build the query to get the default unit
    
            var pagecontext = Xrm.Page.context;
            var serverUrl = pagecontext.getServerUrl();
            var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
            var oDataSelect = oDataPath + "ProductSet?$select=DefaultUoMId&$filter=ProductId eq guid'" + productFieldId + "'";
    
            //alert(oDataSelect );
    
            //Start AJAX call to get default unit guid from product
    
            $.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) {
                    NowHaveDefaultUnitGuid(data, status, productFieldId, oDataPath);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert("OData Select Failed: " + errorThrown + ". There is no default unit associated with product");
                }
            });
        }
    }
    
    function NowHaveDefaultUnitGuid(data, status, productFieldId, oDataPath) {
    
        //we are passing the oDataPath and productFieldId since we will still need these variables
    
        var defaultUnitGUID = data.d.results[0].DefaultUoMId; //retrieved defaultUnit guid
        var opportunityId = Xrm.Page.getAttribute('opportunityid').getValue();
        if (opportunityId != null) {
            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) {
                    NowWeHaveEverything(data, status, productFieldId, defaultUnitGUID, oDataPath);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert('OData Select Failed: ' + errorThrown + ". There is no parent price list");
                }
            });
        }
    }
    
    function NowWeHaveEverything(data, status, productFieldId, defaultUnitGUID, oDataPath) {
    
        //now that we have the pricelist guid, default unit guid, we can lookup the price list item to pull the amount value
    
        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'" + defaultUnitGUID.Id + "')";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataSelect2,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, status) {
                havePrice(data, defaultUnitGUID);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert('OData Select Failed: ' + errorThrown + ". There is no price list item for this product");
            }
        });
    }
    
    function havePrice(data, defaultUnitGUID) {
        if (defaultUnitGUID != 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;
            //set the unit on Opportunity below.
            var id = defaultUnitGUID.id;
            var name = defaultUnitGUID.Name.toString();
            var entityType = defaultUnitGUID.LogicalName.toString();
            Xrm.Page.getAttribute("uomid").setValue([{
                    id: id,
                    name: name,
                    entityType: entityType
                }
            ]);
        }
    }

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, May 1, 2013 5:53 PM
    Moderator