Hi Seren, thanks for your answer, quick question this mapTable should be my retrieved value variable, right? I mean I have this script to get the value which is stored on this variable global "CompanySizePicklistValue_Retrieved"
/*************** Get Account Data Start ***************/
if (getAccountId){
var AccountInfo = my.oData.GetEntityRecords("Account", null, "IsCustomerAccount,IndustryLookupField,CompanySizAccountField,AccountId", "AccountId eq (guid'" + getAccountId[0].id + "')", false, null, null, null);
if (getAccountId != null && getAccountId[0] != null) {
var accountId = getAccountId[0].id.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
var CompanySizePicklistValue_Retrieved;
var CustomerSize_FinalValue;
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accountId + ")?$select=CompanySizAccountField", true);
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) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
CompanySizePicklistValue_Retrieved = result[PickListField];
/*** Here i need to transform the retrieved value from the picklistfield to the CustomerSize Final Value to set that
into the JSON data section ***/
switch(CompanySizePicklistValue_Retrieved){
case 1:
CustomerSize_FinalValue = 1;
break;
case 2:
CustomerSize_FinalValue = 51;
break;
case 3:
CustomerSize_FinalValue = 52;
break;
case 4:
CustomerSize_FinalValue = 53;
break;
case 5:
CustomerSize_FinalValue = 54;
break;
case 6:
CustomerSize_FinalValue = 55;
break;
default:
alert("No Company Size data on account, please help us updating the information. Thanks!");
break;
}
return CustomerSize_FinalValue;
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
if (AccountInfo && AccountInfo[0].IndustryLookupField.Id != null){
var Industry = new Array();
Industry[0] = new Object();
Industry[0].id = "{" + AccountInfo[0].IndustryLookupField.Id + "}";
Industry[0].name = AccountInfo[0].IndustryLookupField.Name;
Industry[0].entityType = AccountInfo[0].IndustryLookupField.LogicalName;
}else{
alert("The customer doesn't contain an industry, please fill the field on the account record.");
}
}
}
/*************** Get Account data end ***************/
So, in order to do a map with this field, I have to do something like this:
CompanySizePicklistValue_Retrieved = [1, 1],
[2, 52] etc...
and then the function to retrieve this to the final value and put it into my Json, right?