Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output Enum int-values instead of/as well as strings #55

Closed
jespertheil opened this issue Oct 27, 2023 · 14 comments · Fixed by #69
Closed

Output Enum int-values instead of/as well as strings #55

jespertheil opened this issue Oct 27, 2023 · 14 comments · Fixed by #69

Comments

@jespertheil
Copy link

jespertheil commented Oct 27, 2023

I have had a request from one of the consumers of our data lake if we can support outputting the option fields as their numeric value instead of the corresponding text.
Has anybody met that requirement and maybe looked at a solution. My thought is that the ideal would be to output both as separate columns.

/Jesper

@Bertverbeek4PS
Copy link
Owner

Hi @jespertheil, I haven't heard of it.
But if you have the export of the numbers instead of the values. I expect that the customer then also want to have the values but in another file or table?

Why do they want to have the numbers instead of the values?

@jespertheil
Copy link
Author

Most consumers are fine with the texts, but one wanted something that wouldnt be affected by translations. I think it should be possible to output both numbers and value as text. I'll look into it when I have a dev resource available, just curious if anyone else had similar requests.

@Bertverbeek4PS
Copy link
Owner

Well maybe creating a switch if you want to export numbers or text.
But if you want to to export only the numbers. We can create a extra table that inserts the enums/options with values and translated text.

@jespertheil
Copy link
Author

jespertheil commented Nov 1, 2023

I added the below few modifications which solves our need and outputs 2 columns for options fields, one column as now named Field-XX with the text-representation and another column named Field-XX-val with the option numeric value. The added column is added both to the csv file and to the manifest.

In Util.Codeunit.al:
procedure CreateCsvHeader right after "FieldsAdded += 1" :

            if FieldRef.Type = FieldRef.Type::Option then begin
                FieldTextValue := FieldTextValue + '-val";
                Payload.Append(StrSubstNo(CommaPrefixedTok, FieldTextValue));
                FieldsAdded += 1;
            end;
procedure CreateCsvPayload right after "FieldsAdded += 1" :
             if FieldRef.Type = FieldRef.Type::Option then begin
                Payload.Append(StrSubstNo(CommaPrefixedTok, ConvertOptionFieldToValueText(FieldRef)));
                FieldsAdded += 1;
            end;
New function:
      procedure ConvertOptionFieldToValueText(FieldRef: FieldRef): Text
      var
          DateTimeValue: DateTime;
      begin
          case FieldRef.Type of
              FieldRef.Type::Option:
                  exit(ConvertNumberToText(FieldRef.Value()));
          end;
      end;

In CDMUtil.Codeunit.al :
procedure CreateAttributes right before the end; statement in the foreach loop:

  if FieldRef.Type = FieldRef.Type::Option then 
                Result.Add(
                    CreateAttributeJson(
                        ADLSEUtil.GetDataLakeCompliantFieldName(FieldRef.Name, FieldRef.Number)+'-val',
                        'Int32',
                        FieldRef.Name+' value',
                        AppliedTraits));
  

I've attached the two modified files. If someone were to incorporate this in the BC2ADLS module it should maybe be controlled by an option if you want to output option values like this.

src.zip

/Jesper

@Bertverbeek4PS
Copy link
Owner

Thanks @jespertheil I will look at it after this week when I'm back from Directions.

@Bertverbeek4PS
Copy link
Owner

@jespertheil could you look at branche https://github.com/Bertverbeek4PS/bc2adls/tree/55-output-enum-int-values-instead-ofas-well-as-strings
I have created a extra table for all the enums in the language that the user is running in.
It adds this table also to the ADLSE tables and export it to Fabric or DataLake

@jespertheil
Copy link
Author

I can see that would work too, and be a better option for multi-lingual instances. But wouldn't it then make sense to output the enum-id instead of the text value for the other tables? Or make that an option as you also suggested above, that would be more intuitive to me.

I'm sorry I can't test the solution since I don't have a BC instance (I don't code in BC anymore - that's at least 12 years ago :)), but I can ask someone to look at it next week.

@Bertverbeek4PS
Copy link
Owner

That is maybe also an option. But I thought this is a better design if we want to extend it with multiple languages.
In the export are all the necessary fields. Like table id, name, field id, name, enum id and caption.

@jespertheil
Copy link
Author

jespertheil commented Dec 21, 2023 via email

@Bertverbeek4PS
Copy link
Owner

Sorry @jespertheil I now understand it.
Very sorry for the confusion!
Lett me think of it. Maybe a switch is a solution that you propose! Also now with the new option of exporting translation it will be a better option to have this one also.

Maybe next week I will take a look and do an proposal.

Thanks! And sorry again for the confusion.
And have also a happy Christmas!

@Bertverbeek4PS
Copy link
Owner

@jespertheil I have created Pull Request:
#71

Can you take a look at it?
Tested it and everything went OK.

@jespertheil
Copy link
Author

@Bertverbeek4PS
From the code, it looks like :

  • An option on ADLSESetup to choose whether to export enums as text or values
  • Export functions look at this option and outputs either/or

I think this is a good solution, but would prefer being able to output both text and value - that is what we do at the moment.
I am off for the holidays so wont be able to test in practice before the new year.

@Bertverbeek4PS
Copy link
Owner

@jespertheil thanks!
But in that case you can get the value from the translation file also in the correct language.

Ok I will wait until you have tested also.
Happy holidays!

@Bertverbeek4PS
Copy link
Owner

Added this in the newest release:
https://github.com/Bertverbeek4PS/bc2adls/releases/tag/2.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants