HI all,
I'm having an issue with the following code, and hope one of you can point out what i have wrong. The code runs and i see my first alert but don't get the second.
function setCaseCompany() { //Get the Resource lookup off of the record var resource = Xrm.Page.getAttribute('msdyn_bookableresourceid').getValue(); //if contact exist, attempt to pull back the contact record if (resource != null) { var resourceId = resource[0].id; var serverUrl; if (Xrm.Page.context.getClientUrl !== undefined) { serverUrl = Xrm.Page.context.getClientUrl(); } else { serverUrl = Xrm.Page.context.getServerUrl(); } alert("here"); var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc"; var rollRequest = new XMLHttpRequest(); rollRequest.open("GET", ODataPath + "/BookableResourceSet(guid'" + resourceId + "')", false); rollRequest.setRequestHeader("Accept", "application/json"); rollRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8"); rollRequest.send(); //If request was successful, parse the associated record name if (rollRequest.status == 200) { alert("Here"); var retrievedRoll = JSON.parse(rollRequest.responseText).d; alert(retrievedRoll.rev_defaultroleId); if (retrievedRoll != null && retrievedRoll.new_defaultrole != null) { alert('NOT HERE!'); //set the value of the field to the field “new_defaultrole” var lookup = new Object(); var lookupValue = new Array(); lookup.id = retrievedRoll.new_defaultrole.Id; lookup.entityType = "bookableresourcecategory"; lookup.name = retrievedRoll.new_defaultrole.Name; lookupValue[0] = lookup; Xrm.Page.getAttribute("msdyn_resourcecategory").setValue(lookupValue); Xrm.Page.getControl("msdyn_resourcecategory").clearNotification(); } else { } } else { } } else { } }
Error message:
Error: parameter is not passed or parameter is nNull or undefined at Function.Error.create