Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Modifying Enum Value in Query

(3) ShareShare
ReportReport
Posted on by 255
I am trying to create a List page that combines BC Sales Header & Invoice Data with GP Data migrated from the Dynamics GP Intelligent Cloud.
 
I have built a Temporary Table to store the contents of the data I need displayed, and built 2 Queries to retrieve the data from the tables.  I am using the trigger OnOpenPage and  Query.Open & Query.Read in the Page to retrieve the data from the Queries
 
The first Query gets all of the BC table data, including the Enum Sales Document Type values.
The second Query performs a similar task on the GP data.
 
The problem exists with the Enum values for the Sales Document Types.  In BC, the Enum values and names do not match the GP values & names. See below example.
 
Order Type BC Enum GP Enum
Quote 0 1
Order 1 2
Invoice 2 3
Credit Memo 3 4
 
What I would like to do in the GP Query is change the column results so they match the Enum values of the BC data.  For Instance:
  • If GP value = 1, then 0 (Quote)
  • If GP value = 2, then 1 (Order)
  • If GP value = 3, then 2 (Invoice)
  • If GP value = 4, then 3 (Credit Memo)
Where and how is the correct way to change the GP values that will be displayed in the Page to match BC values?  Can I change the GP values somewhere in the Query.Read loop, or somewhere within the Query itself?
  • Suggested answer
    Sohail Ahmed Profile Picture
    4,844 on at
    Modifying Enum Value in Query
    Hope this might be helpful:

    The most effective way to align your Dynamics GP "Sales Document Type" values with Business Central's Enum values for display on your List Page is to perform a data transformation during the Query.Read loop, before inserting into your temporary table.

    This ensures your temporary table stores consistent BC Enum values, allowing for proper display and filtering.

    Here's how to do it within your OnOpenPage trigger:

     

     

    OnOpenPage()
    var
        BCQuery: Query "Your BC Sales Query"; // Your first query for BC data
        GPQuery: Query "Your GP Sales Query"; // Your second query for GP data
        TempCombinedSales: Record "Your Temporary Table" temporary; // Your temporary table
        BCSalesDocType: Enum "Sales Document Type"; // Define the BC Enum type
    begin
        // Process BC Data (assuming it's already in the correct Enum format)
        BCQuery.Open();
        while BCQuery.Read() do begin
            // Populate TempCombinedSales from BCQuery.
            // TempCombinedSales.DocumentType := BCQuery.DocumentType; // Directly assign if BC Query returns Enum
            // ... populate other fields ...
            // TempCombinedSales.Insert();
        end;
        BCQuery.Close();
    
        // Process GP Data and translate document types
        GPQuery.Open();
        while GPQuery.Read() do begin
            TempCombinedSales.Init();
            // ... populate other fields from GPQuery ...
    
            // Translate GP Document Type (Integer) to BC Enum Value
            case GPQuery."GP Document Type Field" of // Assume GPQuery has a field for document type, e.g., an integer
                1: BCSalesDocType := BCSalesDocType::Quote;
                2: BCSalesDocType := BCSalesDocType::Order;
                3: BCSalesDocType := BCSalesDocType::Invoice;
                4: BCSalesDocType := BCSalesDocType::"Credit Memo"; // Ensure exact enum member name
                else
                    // Handle unknown GP types if necessary, e.g., set to a default or skip
                    BCSalesDocType := BCSalesDocType::Order; // Default example
            end;
    
            TempCombinedSales.DocumentType := BCSalesDocType;
            TempCombinedSales.Insert();
        end;
        GPQuery.Close();
    
        // Set the page source to the temporary table
        CurrPage.SetRecord(TempCombinedSales);
    end;
    

    By implementing this CASE statement within the loop where you read GP data, you directly map the GP numerical values to the corresponding Business Central Enum members before inserting them into your temporary table. This ensures data consistency for display and further processing on your List Page.

    ✅ Mark this answer as verified if it helps you.

  • ME-31032107-0 Profile Picture
    255 on at
    Modifying Enum Value in Query
    , so simple, thank you!
  • Verified answer
    Ramesh Kumar Profile Picture
    5,503 on at
    Modifying Enum Value in Query
    In your OnOpenPage() trigger where you read the GP query data, add a CASE statement (or IF) to translate the GP values to BC enum values before storing them in your temporary table.
     
    trigger OnOpenPage()
    var
        BCQuery: Query "Your BC Query";
        GPQuery: Query "Your GP Query";
        TempRec: Record "Your Temp Table";
    begin
        // Read GP data and normalize enum
        GPQuery.Open;
        while GPQuery.Read do begin
            TempRec.Init;
            TempRec."Document No." := GPQuery."Document No.";
            case GPQuery."GP Doc Type" of
                1: TempRec."Doc Type" := Enum::"Sales Document Type"::Quote;
                2: TempRec."Doc Type" := Enum::"Sales Document Type"::Order;
                3: TempRec."Doc Type" := Enum::"Sales Document Type"::Invoice;
                4: TempRec."Doc Type" := Enum::"Sales Document Type"::"Credit Memo";
                else TempRec."Doc Type" := Enum::"Sales Document Type"::"Blank";
            end;
            // Assign other fields...
            TempRec.Insert();
        end;
        GPQuery.Close;
    end;
     
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans