With CRM 2011 Update 11 I need to stop using .Value (blue issue http://blogs.msdn.com/b/crm/archive/2012/06/21/microsoft-dynamics-crm-2011-custom-code-validation-tool-released.aspx)
Can't see how to expose recordstatus.Value by another method
Thanks
var validationResult=true; function ValidateStatusOnSave(context) { // Get the CRM URL //debugger; var serverUrl = Xrm.Page.context.getServerUrl(); // Cater for URL differences between on premise and online if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); } var guidvalue = Xrm.Page.data.entity.attributes.get("abc_currentrecord_id").getValue()[0].id; // Specify the ODATA end point (this is the same for all CRM 2011 implementations) var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; // Specify the ODATA entity collection (this needs to be specific to your entity) var ODATA_EntityCollection = "/abc_relatedrecordSet"; // Specify the ODATA filter var ODATA_Query = "?$select=abc_Status&$filter= abc_relatedrecordid eq (guid'" + guidvalue + "')"; // Build the URL var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query; //Calls the REST endpoint - need to set to synchronous in order to control form save event $.ajax({ type: "GET", async: false, contentType: "application/json; charset=utf-8", datatype: "json", url: ODATA_Final_url, beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { //This function will trigger synchronously if the Retrieve was successful GetResults(data.d); }, error: function (XmlHttpRequest, textStatus, errorThrown) { //This function will trigger synchronously if the Retrieve returned an error alert("Problem with validation function - ajax call failed"); } }); if (!validationResult) { context.getEventArgs().preventDefault(); return false; } else { event.returnValue=true; return true; } } function GetResults(OneEntity) { var oneEntity=OneEntity.results[0]; var recordstatus=oneEntity.abc_Status; if (recordstatus.Value==753560001 ) { alert("You cannot save the record with the status as set in the related record"); validationResult=false; return false; } else validationResult=true; }