web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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 683
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?
I have the same question (0)
  • Verified answer
    Ramesh Kumar Profile Picture
    7,527 Super User 2025 Season 2 on at
    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.
  • ME-31032107-0 Profile Picture
    683 on at
    , so simple, thank you!
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,148 Super User 2025 Season 2 on at
    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.

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

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans