Skip to content

Commit

Permalink
Fixed: parser issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Elsawalhy committed Oct 10, 2024
1 parent 7c161f2 commit 485d15b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion PluginRegExt-Config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SelectedSettingsIndex": 0,
"SelectedSettingsIndex": 1,
"SettingsList": [
{
"Id": "ac0ccae1-366f-4731-bbf7-2613db31464e",
Expand Down
48 changes: 29 additions & 19 deletions Yagasoft.AutoNumbering.Plugins/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3926,24 +3926,34 @@ protected override object InnerEvaluate(GlobalState state, object baseValue = nu
case Entity entity:
{
var value = entity.GetAttributeValue<object>(property);
return value switch {
Guid id => id.ToString().ToLower(),
Money money => (double)money.Value,
decimal dec => (double)dec,
float flo => (double)flo,
OptionSetValue choice => new ChoiceParams(entity, choice, property),
null => entity.Contains(property)
? null
: entity.IntegrateAttributes(state.Service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(property)))
.GetAttributeValue<object>(property),
"name" =>entity["name"] = CrmHelpers
.GetRecordName(state.Service, entity, true, null, state.OrgId),
"logical" => entity.LogicalName,
"id" => entity.Id.ToString().ToLower(),
"url" => entity["url"] = CrmHelpers
.GetRecordUrl(state.Service, entity.ToEntityReference(), state.OrgId),
_ => value
};

object ParseAttribute(object attribute = null)
{
return attribute switch {
Guid id => id.ToString().ToLower(),
Money money => (double)money.Value,
decimal dec => (double)dec,
float flo => (double)flo,
OptionSetValue choice => new ChoiceParams(entity, choice, property),
null => entity.Contains(property)
? null
: entity.IntegrateAttributes(state.Service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(property)))
.GetAttributeValue<object>(property),
"name" =>entity["name"] = CrmHelpers
.GetRecordName(state.Service, entity, true, null, state.OrgId),
"logical" => entity.LogicalName,
"id" => entity.Id.ToString().ToLower(),
"url" => entity["url"] = CrmHelpers
.GetRecordUrl(state.Service, entity.ToEntityReference(), state.OrgId),
_ => value
};
}

// try to retrieve
var parsedValue = ParseAttribute(value);

// if retrieved, parse again to the supported types
return value == null ? ParseAttribute(parsedValue) : parsedValue;
}

case EntityReference reference:
Expand All @@ -3961,7 +3971,7 @@ protected override object InnerEvaluate(GlobalState state, object baseValue = nu
? label :
MetadataHelpers.GetOptionSetLabel(state.Service, choice.Row.LogicalName, choice.Property,
choice.Choice.Value, state.Lcid, state.OrgId),
"value" => choice.Choice.Value,
"value" => (double)choice.Choice.Value,
_ => throw new NotSupportedException($"Choice property '{property}' is not supported.")
};

Expand Down

0 comments on commit 485d15b

Please sign in to comment.