lookupSet & bidResult

mail@pastecode.io avatar
unknown
javascript
2 years ago
3.3 kB
1
Indexable
Never
var productCategoryLookup = new Array();
productCategoryLookup[0] = new Object();
productCategoryLookup[0].id = rms_productcategoryid_value;
productCategoryLookup[0].name = rms_productcategoryid_value_formatted;
productCategoryLookup[0].entityType = "rms_productcategory"; 
Xrm.Page.getAttribute('rms_productcategoryid').setValue(value);



function bidResult_onChange(executionContext) {
    var formContext = executionContext.getFormContext();

    var bidResult = formContext.getAttribute('rms_bidresult').getValue();
    
    if(bidResult == 0)
    {
        var proposalId = formContext.data.entity.getId();
        Xrm.WebApi.online.retrieveMultipleRecords("quotedetail", `?$select=_productid_value,productname,producttypecode,_quoteid_value,productdescription&$filter=_quoteid_value eq ${proposalId}`).then(
            function success(results) {
                console.log(results);
                if(results?.entities?.length > 0){
                    for (var i = 0; i < results.entities.length; i++) {
                        var item = results.entities[i];
                        
                        var proposalProductId = item["quotedetailid"];
                        var existingProductId = item["_productid_value"]; 
                        var existingProductIdName = item["_productid_value@OData.Community.Display.V1.FormattedValue"];
                        var writeInProductName = item["productdescription"]; 
                        var productName = item["productname"]; 
                        var sectorCode = item["rms_sectorcode"];                     
                        var productCategoryId = item["_productid_value"]; 
                        var productCategoryIdName = item["_productid_value@OData.Community.Display.V1.FormattedValue"];
                        var proposalId = item["_quoteid_value"]; 
                        var proposalIdName = item["_quoteid_value@OData.Community.Display.V1.FormattedValue"];
                    
                        var winLossProduct = {};

                        winLossProduct.rms_writeinproduct = writeInProductName;
                        winLossProduct.rms_productname = productName;
                        winLossProduct.rms_sectorcode = sectorCode; 
                        winLossProduct["rms_existingproductid@odata.bind"] = `/products(${existingProductId})`;
                        winLossProduct["rms_productcategoryid@odata.bind"] = `/rms_productcategories(${productCategoryId})`; 
                        winLossProduct["rms_quotedetailid@odata.bind"] = `/quotedetails(${proposalProductId})`; 
                        Xrm.WebApi.online.createRecord("rms_winlossanalysis", record).then(
                            function success(result) {
                                var newId = result.id;
                                console.log("winLoss kalemi oluşturuldu",newId);
                            },
                            function (error) {
                                console.log(error.message);
                            }
                        );                       
                    }
                }
            },
            function (error) {
                console.log(error.message);
            }
        );
    }
}