Hello,
I have a requirement to convert a two letter state code into an optionset value in a jscript web resource. This is not being done on a form with the optionset on it.
Before I head down the rabbit hole, is there already a built-in function for doing this? Get value from text, get text from value from a Global Optionset?
If not, it would seem that I need to do this via a XMLHttpRequest? I could not see any XRM functions that would do this?
If XMLHttpRequest is the correct path, I have not been able to make it work.
I have had success with this call in Postman: https://sandbox.crm.dynamics.com/api/data/v9.1/GlobalOptionSetDefinitions(Name='tpr_statesprovidences') This does return all of the options in json format.
I have tried several variations of this code:
=====
var apiURL = clientURL + "/api/data/v9.1/GlobalOptionSetDefinitions(Name='tpr_statesprovidences')";
var tableOptions;
var req = new XMLHttpRequest();
req.open ("GET", apiURL, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange == function ()
{
if (this.readyState == 4 /* complete*/ )
{
console.log("Made It Here Too", "");
req.onreadystatechange = null;
if (this.status == 200)
{
//tableOptions = JSON.parse(this.responseText);
var result = JSON.parse(this.response);
tableOptions = result;
}
else
{
var error = JSON.parse(this.response).error;
}
}
};
=====
I never get to the console.log statement.
Can anyone help with the simplest way to achieve this requirement?
Thanks.
Bryan Hunt