Skip to content

Commit

Permalink
Implemented #38 (multi select option sets) and #39 (translation of op…
Browse files Browse the repository at this point in the history
…tion set value descriptions)
  • Loading branch information
Florian Krönert authored and Florian Krönert committed Nov 12, 2021
1 parent 242e041 commit cddc2d4
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/js/Translator/OptionSetHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@
return id.substring(0, separatorIndex);
}

function GetComponent () {
var component = XrmTranslator.GetComponent();

if (component === "DisplayName") {
return "Label";
}

return component;
}

function GetOptionValueUpdate (attribute, value, labels) {
if (!attribute.GlobalOptionSet && !attribute.OptionSet) {
throw new Error("Either the global option set or the OptionSet have to be passed!");
}

var updateComponent = GetComponent();

var update = {
Value: value,
Label: {
[updateComponent]: {
LocalizedLabels: labels
},
MergeLabels: true
Expand Down Expand Up @@ -150,7 +162,7 @@

for (var j = 0; j < options.length; j++) {
var option = options[j];
var labels = option.Label.LocalizedLabels;
var labels = option[GetComponent()].LocalizedLabels;

var child = {
recid: record.recid + idSeparator + option.Value,
Expand Down Expand Up @@ -219,9 +231,15 @@
queryParams: "/Attributes/Microsoft.Dynamics.CRM.StatusAttributeMetadata?$expand=OptionSet,GlobalOptionSet"
};

return WebApiClient.Promise.all([WebApiClient.Retrieve(optionSetRequest), WebApiClient.Retrieve(booleanRequest), WebApiClient.Retrieve(statusRequest)])
var multiOptionSetRequest = {
entityName: "EntityDefinition",
entityId: entityMetadataId,
queryParams: "/Attributes/Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata?$expand=OptionSet,GlobalOptionSet"
};

return WebApiClient.Promise.all([WebApiClient.Retrieve(optionSetRequest), WebApiClient.Retrieve(booleanRequest), WebApiClient.Retrieve(statusRequest), WebApiClient.Retrieve(multiOptionSetRequest)])
.then(function(responses){
var responseValues = responses[0].value.concat(responses[1].value).concat(responses[2].value);
var responseValues = responses[0].value.concat(responses[1].value).concat(responses[2].value).concat(responses[3].value);
var attributes = responseValues.sort(XrmTranslator.SchemaNameComparer);

XrmTranslator.metadata = attributes;
Expand Down

0 comments on commit cddc2d4

Please sign in to comment.