Answered by:
CRM 2013 odata Request not working

Question
-
Hi, Can someone review and let me know why this query isn't working?
theirs a field called new_task on the account and the same one on the Task entity, the optionssets are global so have the same values.
function setType() { var lookup = Xrm.Page.getAttribute("regardingobjectid").getValue(); if (lookup != null) { var lookupid = lookup[0].id; var serverUrl; if (Xrm.Page.context.getClientUrl !== undefined) { serverUrl = Xrm.Page.context.getClientUrl(); } else { serverUrl = Xrm.Page.context.getServerUrl(); } var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc"; var dataRequest = new XMLHttpRequest(); dataRequest.open("GET", ODataPath + "/AccountSet(guid'" + lookupid + "')", false); dataRequest.setRequestHeader("Accept", "application/json"); dataRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8"); dataRequest.send(); if (dataRequest.status === 200) { var retrievedValue = JSON.parse(dataRequest.responseText).d; var value = retrievedValue.new_type; Xrm.Page.getAttribute("new_type").setValue(value); Xrm.Page.getAttribute("new_type").setSubmitMode("always"); } else { return "error"; } } }
Pete
- Edited by Pete.CRM Monday, January 6, 2014 12:16 PM
Monday, January 6, 2014 12:15 PM
Answers
-
Hi Pete,
did you check if retrievedValue returns some value? (you can do an alert)
and check if new_type is the right name, this because REST endpoint use schema name, maybe your field name is new_Type.
also do an alert of value variable, because your field type is optionset currently I don't remember how optionset are returned from a REST query.
My blog: www.crmanswers.net - Rockstar 365 Profile
- Marked as answer by Pete.CRM Tuesday, January 7, 2014 8:21 AM
Monday, January 6, 2014 12:42 PM
All replies
-
Hello,
In case field new_type is optionset then you should get value using following code:
var value = null; if (retrievedValue.new_type != null && retrievedValue.new_type.Value != null){ value = retrievedValue.new_type.Value; }
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blog- Proposed as answer by Guido PreiteMVP Monday, January 6, 2014 12:43 PM
Monday, January 6, 2014 12:39 PMModerator -
Hi Pete,
did you check if retrievedValue returns some value? (you can do an alert)
and check if new_type is the right name, this because REST endpoint use schema name, maybe your field name is new_Type.
also do an alert of value variable, because your field type is optionset currently I don't remember how optionset are returned from a REST query.
My blog: www.crmanswers.net - Rockstar 365 Profile
- Marked as answer by Pete.CRM Tuesday, January 7, 2014 8:21 AM
Monday, January 6, 2014 12:42 PM -
the issue was the schema name was slightly different, thanks Guido :)
Pete
Tuesday, January 7, 2014 8:21 AM -
If I want to retrieve two or more different values from different fields, how can I do that?
For example one option set value, and one textfield value.
Tuesday, January 7, 2014 11:40 AM