Home

Apr 11, 2013

Setting default pricelist for an entity

You can use SDK.JQuery.js file which comes with sdk. Here is the code to set the default pricelist with name start with “Default”
 
//set default price list for opportunity
function setDefaultPriceList() {
    var defaultPriceListStartsWith = "Default";
    SDK.JQuery.retrieveMultipleRecords("PriceLevel",
                                "?$filter=startswith(Name, '" + defaultPriceListStartsWith + "')",
                                function (retrievedPriceLists) {
                                    if (retrievedPriceLists.length > 0) {
                                        setPriceList(retrievedPriceLists[0]);
                                    }
 
                                },
                                errorHandler,
                                onCompleteRetrieveMultiple
                                );
}
 
//set pricelist for opportunity
function setPriceList(priceList) {
    if (priceList != null) {
        var defaultPriceListAttrib = Xrm.Page.getAttribute("pricelevelid");
        if (defaultPriceListAttrib.getAttributeType() == "lookup") {
            setSimpleLookupValue("pricelevelid", "pricelevel", priceList.PriceLevelId, priceList.Name);
        }
    }
}
// set lookup value
function setSimpleLookupValue(LookupId, Type, Id, Name) {
    var lookupReference = [];
    lookupReference[0] = {};
    lookupReference[0].id = Id;
    lookupReference[0].entityType = Type;
    lookupReference[0].name = Name;
    Xrm.Page.getAttribute(LookupId).setValue(lookupReference);
}
 
 

1 comment:

sandeep samuel said...

Hi Amol,

Nice dynamics crm blog,thanks for sharing this article. looking forward for more articles like this.










Dynamics CRM Developers