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

Creating a CRM 2011 record using SDK REST - Option Set Issue

$
0
0

I've been reading and testing and just cannot figure our what I am doing wrong.  I am using SDK.REST and everything else appears to be working fine.  The code has all the failed attempts commented out with FAIL.

function CreatePOLineV2() {
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    var CRMObject = {}; // new Object();
    var ODATA_EntityCollection = "solpas_purchaseorderline"; //"/solpas_purchaseorderlineSet"
    var oQty = Xrm.Page.data.entity.attributes.get("solpas_itemqty");
    var oItem = Xrm.Page.data.entity.attributes.get("solpas_itemnumber");
    var oShDesc = Xrm.Page.data.entity.attributes.get("solpas_itemshortdescription");
    CRMObject.solpas_name = "00-" + oItem.getValue();
    CRMObject.solpas_ShortDescription = oShDesc.getValue();
    CRMObject.solpas_Qty = oQty.getValue().toString(10);

    // PO Number Lookup
    var oPO = Xrm.Page.data.entity.attributes.get("solpas_name");
    var strName = oPO.getValue();
    var oID = Xrm.Page.data.entity.getId();
    CRMObject.solpas_PONumberId = { Id: oID, LogicalName: "solpas_po", Name: oPO.getValue() };
    // House Part from global array aItem
    if (aItem != null) {
        CRMObject.solpas_HousePartId = { Id: aItem[0].id, LogicalName: "solpas_part", Name: aItem[0].name };
    }
    // Unit
    var oU = Xrm.Page.getAttribute("solpas_forunitid");
    if (oU != null) {
        var oUValue = oU.getValue();
        if (oUValue != null) {
            CRMObject.solpas_UnitId = { Id: oUValue[0].id, LogicalName: "solpas_unit", Name: oUValue[0].name };
        }
    }
    // Supplier Lookup
    var oSup = Xrm.Page.getAttribute("solpas_supplierid");
    if (oSup != null) {
        var oSupValue = oSup.getValue();
        if (oSupValue != null) {
            CRMObject.solpas_SupplierId = { Id: oSupValue[0].id, LogicalName: "account", Name: oSupValue[0].name };
        }
    }
    // Prices and Amounts
    CRMObject.solpas_Price = { Value: Xrm.Page.data.entity.attributes.get("solpas_price").getValue().toString() };
    CRMObject.solpas_ExtendedAmount = { Value: Xrm.Page.data.entity.attributes.get("solpas_extendedamount").getValue().toString() };
    if (Xrm.Page.data.entity.attributes.get("solpas_corechargeapplies").getValue()) {
        CRMObject.solpas_CoreChargeApplies = true; // { Value: true };
    } else {
    CRMObject.solpas_CoreChargeApplies = false; // { Value: false };
    }
    CRMObject.solpas_CoreCharge = { Value: Xrm.Page.data.entity.attributes.get("solpas_corecharge").getValue().toString() };
    CRMObject.solpas_LaborCharge = { Value: Xrm.Page.data.entity.attributes.get("solpas_laborcharge").getValue().toString() };
    CRMObject.solpas_SHAmount = { Value: Xrm.Page.data.entity.attributes.get("solpas_shamount").getValue().toString() };
    CRMObject.solpas_TotalAmount = { Value: Xrm.Page.data.entity.attributes.get("solpas_totalamount").getValue().toString() };
    if (Xrm.Page.data.entity.attributes.get("solpas_forstock").getValue()) {
        CRMObject.solpas_ForStock = true; // { Value: true };
    } else {
        CRMObject.solpas_ForStock = false; // { Value: false };
    }
    // solpas_UOM
    // var strSelectedValue = Xrm.Page.data.entity.attributes.get("solpas_uom").getValue().toString();
    // alert("UOM Opt Set Value:" + strSelectedValue);
    var intSelectedValue = parseInt(Xrm.Page.data.entity.attributes.get("solpas_uom").getValue());
    alert("UOM Opt Set Value:" + intSelectedValue);
    // CRMObject.solpas_UOM = { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue" }, "Value": 491760000 };
    // CRMObject.solpas_UOM = { Value: 491760000 }; //FAIL
    // CRMObject.solpas_UOM = { Value: intSelectedValue.value }; //FAIL
    // CRMObject.solpas_UOM = { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue" }, "Value": 0 }; //FAIL
    // CRMObject.solpas_UOM = { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue" }, "Value": intSelectedValue }; //FAIL
    // CRMObject.solpas_UOM = { "__metadata": { "type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue" }, "Value": intSelectedValue.value }; //FAIL


    CRMObject.solpas_Package = { Value: Xrm.Page.data.entity.attributes.get("solpas_package").getValue().toString() };


    try {
        SDK.REST.createRecord(CRMObject, ODATA_EntityCollection, createCRMObjectCompleted, errorCreate);
    }
    catch (e) {
        alert("An error has occurred: " + e.message);
    }
}

Nothing I do with the solpas_UOM option set appears to work.  I feel I am close with the error of: Error in CreatePOLineV2 SDK.REST.createRecord Call: Error : 500: Internal Server Error: A validation error occurred. The value of 'solpas_uom' on record of type 'solpas_purchaseorderline' is outside the valid range.

Any help would be appreciated - valid help would be greatly appreciated!


Bruce A. Jones Solutects LLC


Viewing all articles
Browse latest Browse all 8223

Trending Articles