Hi,
I am trying to autopoulate a optionset field with the value retrieved through odata query. I can alert all the Optionset values in th SetOptionSetValue function but not able to set the value to the optionset field.
function optionsetDetails() { var contName=Xrm.Page.getAttribute("new_contnew").getValue(); if (contName != null) { var contId = contName[0].id; } var serverUrl=Xrm.Page.context.getClientUrl(); var oDataSelect=serverUrl+"/XRMServices/2011/OrganizationData.svc/new_contSet?$select=new_InterpreterType&$filter=new_lapinterpreterId eq guid'"+contId+"'"; var retrieveReq=new XMLHttpRequest(); retrieveReq.open("GET", encodeURI(oDataSelect), false); retrieveReq.setRequestHeader("Accept", "application/json"); retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8"); retrieveReq.send(); if (retrieveReq.status === 200) { var retrieved = JSON.parse(retrieveReq.responseText).d; if (retrieved != null && retrieved.results.length > 0) { var interpretertype=retrieved.results[0].new_InterpreterType; SetOptionSetValue("new_interpretertype",interpretertype); } } } function SetOptionSetValue(optionsetAttribute,optionValue) { var options=Xrm.Page.getAttribute(optionsetAttribute).getOptions(); for(var i in options) { alert(options[i].value); if(options[i].value==optionValue) { Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value); } } }
I did debug the script and noticed that
if(options[i].value==optionValue)
{
Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);
}
the if condition is evaluated to true for all the options. I don't understand why! and the optionset is displaying nothing.
Thanks