Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

convert "Sell-to Country/Region Code" to "Country Description"

Posted on by 30

Hello Guys.

I've made a reportextension to report 1306, that handles some stuff - mainly the customer data. 

I can get the traditional  "Sell-to Country/Region Code" field on my report, but i can't figure out how to get the "Description" and not the "Code" - like "UK" should be "United Kingdom" 

Any advices here? 

So far i tried setting a Record as the "Country/Region" Table -but can't figure out how to get a return value from the "Description" if i call it with the "Code" - like:

Record.Get('UK') - should return "United Kingdom"

Categories:
  • RasmusAKEA Profile Picture
    RasmusAKEA 30 on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    My bad - worked

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 69,639 Super User 2024 Season 2 on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    Hi, this is related to the Language Code on the invoice, generally this value is from the customer master, but when it is empty, it will take the system default language. So you can modify the Language Code of the customer, and then for the new invoices, it will be printed in English.

    pastedimage1649059607211v1.png

    pastedimage1649060325947v3.png

    pastedimage1649059730906v2.png

    And this is defined by Report.Language([Integer]) Method.

    pastedimage1649060358843v4.png

    More details: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/reportinstance-language-method

    pastedimage1649060451589v5.png

    As you might know, in ReportExtension, we cannot directly modify the OnAfterGetRecord() trigger, we can only use the following two. After a simple test, neither of these can affect the language. So I don't think it's possible to use ReportExtension to fix to English.

    pastedimage1649060476400v6.png

    Hope this info also helps.

    Thanks.

    ZHU

  • Suggested answer
    RasmusAKEA Profile Picture
    RasmusAKEA 30 on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    Thanks for this solution - exactly what i was looking for....

    That solved it from the Code - i then get the Name....

    Wondering if possible to always get the English translation? Now i get it in my local language "Denmark" - would be greater to have returned in English :)

  • RasmusAKEA Profile Picture
    RasmusAKEA 30 on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    Hello Kim - yes exactly that one i was struggling with in the beginning, the problem is it takes the "Contact Name" and include in the address - and i don't want that at all... It takes it even if i make a "Custom" "Country/Area" Definition in the "Country / Area" setup....

    After that i'm making one my self with the correct data i want to have :)

  • YUN ZHU Profile Picture
    YUN ZHU 69,639 Super User 2024 Season 2 on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    Hi, As far as I understand, RasmusAKEA should know how to get the country name in the code, but don't know how to add it to the standard Report.

    Here is an example for report 1306.

    pastedimage1649037234160v1.png

    pastedimage1649037273632v2.png

    pastedimage1649037343453v4.png

    pastedimage1649037311627v3.png

    Source Code: Using Codeunit "Format Address" is also a very good method. For details, you can check the code provided by Igne. .

    reportextension 50133 MyExtension extends "Standard Sales - Invoice"
    {
        dataset
        {
            add(Header)
            {
                column(CountryName; CountryName)
                { }
            }
            modify(Header)
            {
                trigger OnAfterAfterGetRecord()
                var
                    CountryRegion: Record "Country/Region";
                begin
                    if CountryRegion.Get("Sell-to Country/Region Code") then
                        CountryName := CountryRegion.Name;
                end;
            }
        }
    
        var
            CountryName: Text[50];
    }

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    Very good point Kim Dallefeld !

    Here is how you can use that codeunit as well. The only challange with that codeunit is that it is hard to predict where in the textarray the country name will end up. So in some cases i go straight to the source if it is one single filed i am looking for.

    codeunit 50101 "Test Country description"

    {

       trigger OnRun()

       var

           AddressFormat: Codeunit "Format Address";

           SalesInvoice: Record "Sales Invoice Header";

           Country: Record "Country/Region";

           TextArray: array[8] of text[100];

           i: Integer;

       begin

           if SalesInvoice.FindSet() then

               repeat

                   Country.get(SalesInvoice."Sell-to Country/Region Code");

                   Message('The country is %1', Country.Name);

                   AddressFormat.SalesInvSellTo(textarray, SalesInvoice);

                   I := 0;

                   for i := 0 to 7 do begin

                       Message('Address is %1', TextArray[i]);

                       i += 1;

                   end;

               until SalesInvoice.Next() = 0;

       end;

    }

  • Dallefeld Profile Picture
    Dallefeld 11,423 User Group Leader on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"

    There is a code unit that formats the address, whatever you do must happen after the code unit runs. The code unit takes name, name2, address, address2, contact name, city, state, zip and country—removes blank lines, format city, start, zip bars on country code and provides the variables for printing the address. 
    mare you sure the postal service wants the printed name of the country?

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: convert "Sell-to Country/Region Code" to "Country Description"
    Here is a sample codeunit that shows you how to get the name out of the country record.
    The record.get() returnes the whole record and not only the name field.
    codeunit 50101 "Test Country description"
    {
        trigger OnRun()
        var
            SalesInvoice: Record "Sales Invoice Header";
            Country: Record "Country/Region";
        begin
            if SalesInvoice.FindSet() then
                repeat
                    Country.get(SalesInvoice."Sell-to Country/Region Code");
                    Message('The country is %1', Country.Name);
                until SalesInvoice.Next() = 0;

        end;
    }





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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans