How to get the URL for any object in BC

How to get the URL for any object in BC

Sometimes you need the URL for opening a specific page in Business Central. This could be in a scenario where you have an API that exposes all your items, and you want to make it possible for the consumer of the API to make a link directly back to the specific item in Business Central. This of course requires the user to have access to Business Central.

I have made an example of an API page exposing som standard fields from the item table, but in addition to that I also exposes URLs for the item card page for both the web client and the mobile client.

page 50100 ItemAPI
{
    APIGroup = 'bcdev';
    APIPublisher = 'bcdev';
    APIVersion = 'v1.0';
    ApplicationArea = All;
    Caption = 'itemAPI';
    DelayedInsert = true;
    EntityName = 'item';
    EntitySetName = 'items';
    PageType = API;
    SourceTable = Item;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field(no; Rec."No.")
                {
                    Caption = 'No.';
                }
                field(description; Rec.Description)
                {
                    Caption = 'Description';
                }
                field(unitCost; Rec."Unit Cost")
                {
                    Caption = 'Unit Cost';
                }
                field(unitPrice; Rec."Unit Price")
                {
                    Caption = 'Unit Price';
                }
                field(webUrl; WebURL)
                {
                    Caption = 'Url';
                }
                field(phoneUrl; PhoneURL)
                {
                    Caption = 'Url';
                }
            }
        }
    }

    trigger OnAfterGetRecord()
    begin
        WebURL := GetUrl(ClientType::Web, CompanyName, ObjectType::Page, Page::"Item Card", Rec, false);
        PhoneURL := GetUrl(ClientType::Phone, CompanyName, ObjectType::Page, Page::"Item Card", Rec, false);
    end;

    var
        WebURL: Text;
        PhoneUrl: Text;
}        

In this context, is the most important part the 2 lines in the “OnAfterGetRecord” trigger, which uses a built-in function to get the URL for the “Item Card” page, for both the Web and Mobile client, and it does that for every item, and exposes the URLs in the API. Microsoft have made some documentation on the GetUrl function GETURL Function – Dynamics NAV | Microsoft Learn

When calling the API you get a result that looks like the following (I have removed som boilerplate json in the result)

@odata.etag : W/"JzE5OzU3MzYwMzMzOTY0NDk3MjcwOTYxOzAwOyc="
no          : 1896-S
description : ATHEN Skrivebord
unitCost    : 4337
unitPrice   : 5560
webUrl      : https://bcserver-default/BC/?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOAA5ADYALQBT&tenant=bcserver-default
phoneUrl    : ms-dynamicsnav://bcserver-default:80/BC?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOAA5ADYALQBT&tenant=bcserver-default

@odata.etag : W/"JzIwOzE2MTUyNTEzNDI4MjY5ODM3NzEzMTswMDsn"
no          : 1900-S
description : PARIS G?stestol, sort
unitCost    : 835
unitPrice   : 1071
webUrl      : https://bcserver-default/BC/?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOQAwADAALQBT&tenant=bcserver-default
phoneUrl    : ms-dynamicsnav://bcserver-default:80/BC?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOQAwADAALQBT&tenant=bcserver-default

@odata.etag : W/"JzE5OzkzOTY0NTI3MjYwNDAxOTk4NjkxOzAwOyc="
no          : 1906-S
description : ATHEN Skuffemodul
unitCost    : 1879
unitPrice   : 2409
webUrl      : https://bcserver-default/BC/?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOQAwADYALQBT&tenant=bcserver-default
phoneUrl    : ms-dynamicsnav://bcserver-default:80/BC?company=CRONUS%20Danmark%20A%2FS&page=30&bookmark=23%3bGwAAAAJ7%2fzEAOQAwADYALQBT&tenant=bcserver-default        

The source code for this example can be found on my GitHub

要查看或添加评论,请登录

Flemming Bakkensen的更多文章

  • Job Queue Entry Failed, Get Notified on Teams

    Job Queue Entry Failed, Get Notified on Teams

    A notable limitation in Business Central is the monitoring of Job Queue Entries. Although monitoring encompasses a wide…

    1 条评论
  • Add Retention Policy To Your Business Central App

    Add Retention Policy To Your Business Central App

    What is Retention Policy A Retention Policy enables administrators in Business Central to purge data from tables. The…

    1 条评论
  • HOW TO ADD PRICE CALCULATION TO ANY TABLE IN BUSINESS CENTRAL

    HOW TO ADD PRICE CALCULATION TO ANY TABLE IN BUSINESS CENTRAL

    s a Business Central developer, you probably have had the request to add a sales price to a field in a table, and the…

  • HOW TO EXTEND PRICE CALCULATION

    HOW TO EXTEND PRICE CALCULATION

    EXTENDENTING PRICE CALCULATION There is 2 ways to extend Price Calculation in Business Central, either by subscribing…

  • RUN PAGES WITH PAGE MANAGEMENT

    RUN PAGES WITH PAGE MANAGEMENT

    I think most you know about the Page.Run() procedure, and that you by providing zero as the page number and Record…

    1 条评论
  • Use Role Centers as a live dashboard

    Use Role Centers as a live dashboard

    Sometimes you might need a dashboard like page in Business Central. For this purpose you could use Queues on a…

    1 条评论
  • HOW TO CREATE RESERVATIONS AND ITEM TRACKING FROM AL

    HOW TO CREATE RESERVATIONS AND ITEM TRACKING FROM AL

    From my experience Reservations and Item Tracking, in Business Central, is quite often a little confusing, especially…

    2 条评论

社区洞察

其他会员也浏览了