Creating URLs to Microsoft Dynamics NAV Clients

Creating URLs to Microsoft Dynamics NAV Clients

  • Comments 7

The URL builder function, GETURL, is released in Microsoft Dynamics NAV 2013 R2 to reduce coding time for developers who need to create various URL strings to run application objects in either the win client, the web client, or on web services. In addition, the GETURL function makes multitenancy features more transparent to C/AL developers.

Details

Ever had to construct win client URLs like the one below?

dynamicsnav://myserver:7046/myInstance/myCompany/runpage?page=26

Today, Microsoft Dynamics NAV also provides a web client. This means that you must update your code to construct web client URLs too. What about multitenancy? The URL Builder should know if it is running in a multitenant setup and it should know how to choose the right tenant. What about maintaining this code?

The good news is that GETURL has been introduced to handle all URL building for you.

GETURL automatically handles:

  • Multitenancy
  • Correct URL format for each client
  • Publicly accessible hostnames.

Usage

The format is:

[String :=] GETURL(ClientType[, Company][, Object Type][, Object Id][, Record])

Where:

  • Client Type can be: Current, Default, Windows, Web, SOAP, or OData. This enables a range of scenarios for the C/AL developer, such as moving to the web client without changing code to decide where the URL should point to. This is done either by setting Client Type to Current, and just ensuring that web is used to invoke the link creation, or by setting Client Type to Default and changing its value to Web when it is ready to move to the web platform.
  • Object Type and Object ID define the type of the application object to run (Table, Page, Report, Codeunit, Query, or XMLport) and its ID.
  • Record specifies the actual data to run the URL on, such as:

Vendor.GET("Account No.");

GETURL(CLIENTTYPE:WEB,COMPANYNAME, OBJECTTYPE::Page,27,Vendor)

Note: It is currently not possible to set filters on the record that you sent as a last parameter to the GETURL function. However, it is possible to write your own code to compute and append the filter string to the URL that is created by the GETURL function.

The server name and instance are extracted automatically by GETURL and do not need to be specified by the C/AL developer. Furthermore, the multitenancy setup is transparent to the C/AL developer. No multitenancy parameters are specified when you call GETURL, because the function knows from the server setup if it is running in a multitenant environment and if so, it will add a string like "&tenant=MyTenant" to the URL.

When to Use

The GETURL function can generally be used every time a URL must be created. The following are some scenarios where the function is particularly useful.

  • Document approvals. For more information, see the “NAV Usage Example” section.
  • Reports containing drill-down links. (Beware of the resource cost of adding a new URL element to the Report dataset.)
  • When planning to write code for, or migrate to, various display targets (Microsoft Dynamics NAV Windows client, Microsoft Dynamics NAV web client, Microsoft Dynamics NAV web services) without having to explicitly specify which client to use.

Examples of Usage

The following are examples of calls to GETURL and their corresponding return value:

Command

URL

GETURL(CLIENTTYPE::Win)

dynamicsnav://MyServer:7046/DynamicsNAV71//

GETURL(CLIENTTYPE::Web)

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient

GETURL(CLIENTTYPE::OData)

http://MyServer:7048/DynamicsNAV71/OData

GETURL(CLIENTTYPE::SOAP)

http://MyServer:7047/DynamicsNAV71/WS/Services

GETURL(CLIENTTYPE::Current) ie. When running this code on a Win client session

dynamicsnav://MyServer:7046/DynamicsNAV71//

GETURL(CLIENTTYPE::Default) ie. When the Server config key DefaultClient is set to Windows

dynamicsnav://MyServer:7046/DynamicsNAV71//

GETURL(CLIENTTYPE::Windows,COMPANYNAME)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/

GETURL(CLIENTTYPE::Windows,'')

dynamicsnav://MyServer:7046/DynamicsNAV71//

GETURL(CLIENTTYPE::Windows,'NONEXISTING Corp')

dynamicsnav://MyServer:7046/DynamicsNAV71/NONEXISTING Corp/

GETURL(CLIENTTYPE::Web,COMPANYNAME)

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS

GETURL(CLIENTTYPE::Web,'')

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient

GETURL(CLIENTTYPE::Web,'NONEXISTING Corp')

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=NONEXISTING Corp

GETURL(CLIENTTYPE::OData,COMPANYNAME)

http://MyServer:7048/DynamicsNAV71/OData/Company('CRONUS')

GETURL(CLIENTTYPE::OData,'')

http://MyServer:7048/DynamicsNAV71/OData

GETURL(CLIENTTYPE::OData,'NONEXISTING Corp')

http://MyServer:7048/DynamicsNAV71/OData/Company('NONEXISTING Corp')

GETURL(CLIENTTYPE::SOAP,COMPANYNAME)

http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Services

GETURL(CLIENTTYPE::SOAP,'')

http://MyServer:7047/DynamicsNAV71/WS/Services

GETURL(CLIENTTYPE::SOAP,'NONEXISTING Corp')

http://MyServer:7047/DynamicsNAV71/WS/NONEXISTING Corp/Services

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Table,27)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runtable?table=27

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,27)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=27

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Report,6)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runreport?report=6

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Codeunit,5065)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runcodeunit?codeunit=5065

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Query,9150)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runquery?query=9150

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::XmlPort,5150)

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runxmlport?xmlport=5150

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27) ie. When the Web Service is published

http://MyServer:7048/DynamicsNAV71/OData/Company('CRONUS')/PAG27Vendors

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Query,9150)  ie. When the Web Service is published

http://MyServer:7048/DynamicsNAV71/OData/Company('CRONUS')/QUE9150MyCustomers

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27)  ie. When the Web Service is published

http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Page/PAG27Vendors

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Codeunit,5065)  ie. When the Web Service is published

http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Codeunit/COD5065EmailLogging

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,27,record) List Page

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=27&bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw

GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,26,record) Card Page

dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=26&bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,27,record) List Page

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&page=27&bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,26,record) Card Page

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&page=26&bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27,record)

http://MyServer:7048/DynamicsNAV71/OData/Company('CRONUS')/PAG27Vendors('IC1030')

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,27)

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&page=27

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Report,6)

https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&report=6

If the GETURL function is called with invalid parameters, it will return an empty string. In that case, you can find the related error text by calling the GETLASTERRORTEXT function.

Function Call

Error Message

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Table,27)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Codeunit,5065)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Query,9150)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::XmlPort,5150)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Table,27)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27)

The Page object, 27, that is specified for the GetUrl function has not been published in the Web Services table.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Report,6)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Codeunit,5065)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Query,9150)

The Query object, 9150, that is specified for the GetUrl function has not been published in the Web Services table.

GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::XmlPort,5150)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Table,27)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27)

The Page object, 27, that is specified for the GetUrl function has not been published in the Web Services table.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Report,6)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Codeunit,5065)

The Codeunit object, 5065, that is specified for the GetUrl function has not been published in the Web Services table.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Query,9150)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::XmlPort,5150)

The specified object type parameter for the GetUrl function is not valid.

GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27,record)

You cannot specify a record parameter for the GetUrl function when the object type is SOAP

NAV Usage Example

The following example shows how to use the GETURL function in codeunit 440 to ensure that the notification mail in Document Approvals can link to both the Microsoft Dynamics NAV Windows client and the Microsoft Dynamics NAV web client:

This resulting UI looks as follows.

The first link opens the approval document in the Microsoft Dynamics NAV Windows client. The second link (Web view) opens the same document in the Microsoft Dynamics NAV web client.

 

Best regards,

Mike Borg Cardona, Bogdana Botez, and the Microsoft Dynamics NAV team

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • Hi,

    This is extremely helpful function, well done. The only problem is that it does not work all the time.

    For example for approvals I get

    http://DevNav:48900/DynamicsNAV71_Instance1/Webclient?company=Test Company&page=658

    and the correct address should be

    devnav.local/.../list.aspx Company&page=658

    Does CLIENTTYPE:: and GETURL read data from the registry or from a configuration file ?

    It would be very helpful if you could advise where is the data for CLIENTTYPE and GETURL coming from ?

    Thank you.  

  • Hi,

    Thanks for the explanation. But we have an issue where the URL string will point to the internal server. e.g. http://LocalWebServer:8080/DynamicsNAV71/WebClient?company=Cronus. But we need to point it to the external path adhoccomapnywebsite.com/.../WebClient. How do we go about this.

    Thanks,

    Francois

  • Did you try to change the entries under Tools/Options?

  • Hello,

    I am getting exaclty the same error as Vremeni, the URL points to an unknown port, and Instance name includes a "_Instance1" appendix which I don't know where may come from.

    Thanks in advance, Any help will be appreciated.

  • Thanks for your feedback and questions.

    Public\external endpoints may differ from internal addressing. For example, an external port number could map to a different internal port number, or you may be using a domain name to identify your Microsoft Dynamics NAV server. In such cases, the Microsoft Dynamics NAV server instance cannot automatically identify your network configuration settings.

    To solve this problem, find the server instance configuration file and update the configuration keys for base URLs, such as the following key:

       <add key="PublicWebBaseUrl" value="" />

    You can set a Base URL for the Windows client, the web client, as well as SOAP and ODATA services, each independently. For example, you could set the Web Client Base URL to "cronus.nav.net/.../". From this point forward, the GETURL function will return URLs starting with this base address that you have specified.

    Tips and Tricks:

    - Remember to restart the server instance for your change to take effect.

    - You can set server instance configuration keys also using the Microsoft Dynamics NAV PowerShell commandlets or using the Microsoft Dynamics NAV administration console snap-in.

    - When installing Microsoft Dynamics NAV using setup.exe, you can set the base URLs directly in the installation wizard.

    - Take note of the examples provided in the configuration file to ensure you enter URLs using the correct format.

    - In the majority of cases where you have installed the web client, you must set the PublicWebBaseUrl key.

    Best regards,

    Mike Borg Cardona

    Microsoft Dynamics NAV

  • @ Mike Borg Cardona

    I dont get it completely with the address of the web Client - any ideas

    I have entered in

    Web Client Base URL = http://mcdev-nav-fv71:8080/DACH/WebClient%20

    Now GETURL gets the correct starting addresses, but when I run Report 1001 "Inventory Valuation" I can DrillDown to the next Report 5801.

    This causes an error with the filter in the web Client, and without filter everything is okay.

    In the RTC Client the Drilldown directly calls the filtered Report without requets page.

    false:

    http://mcdev-nav-fv71:8080/DACH/Webclient/?company=CRONUS%20AG&report=5801&filter=Item.Field1:1100

    correct call - but no filter:

    http://mcdev-nav-fv71:8080/DACH/Webclient/?company=CRONUS%20AG&report=5801

  • Thank you Mr. Gebauer for the additional question.

    Basically the user gets a server error when clicking the report drilldown in the web client, but not in the Win client.

    This is because the drilldown navigates to another report with a filter.

    Error accessing Website Microsoft Dynamics NAV Crete Web Client

    URL: http://servername:port/instance/Webclient/default.aspx?company=CRONUS%20International%20Ltd.&report=5801&filter=Item.Field1:1100

    Type: Microsoft.Dynamics.Framework.UI.FormActivatorException

    Message: RunReport action has extra unknown parameters.

    StackTrace:

      at Microsoft.Dynamics.Nav.Client.NavRunReportPropertyBagInvokedAction.Validate(FormPropertyBag queryParameters, UISession uiSession, Object invocationState)

      at Microsoft.Dynamics.Framework.UI.LogicalFormActivator.GeneratePropertyBagCommand(FormPropertyBag propertyBagToUse, UISession uiSession, Object invocationState)

      at Microsoft.Dynamics.Framework.UI.LogicalFormActivator.ValidateAndInvokePropertyBag(FormPropertyBag propertyBagToUse, UISession uiSession, Object invocationState)

      at Microsoft.Dynamics.Framework.UI.Web.WebPropertyBagInvoker.InvokeFormPropertyBag(FormPropertyBag propertyBag)

      at Microsoft.Dynamics.Framework.UI.Web.LogicalFormInitializer.<>c__DisplayClass1.<Create>b__0()

      at Microsoft.Dynamics.Framework.UI.LogicalOperationInvoker.InvokeAndHandleExceptions(Func`1 action, IExceptionHandler exceptionHandler)

    Source: Microsoft.Dynamics.Nav.Client.UI

    According to msdn.microsoft.com/.../hh168959(v=nav.71).aspx the Web Client does not support reports with filters in the query string

    The issue is therefore not so much with GETURL generating a wrong URL, or with the Inventory Valuation report specifically, but with the Web Client’s limitations. One could argue that GETURL should never generate a URL which cannot be used, but that won’t help the user perform an easy drilldown without having to type in the ID: basically the drilldowns on this report will *never* work on the Web Client.

    We will look into this in a future release and see if we can somehow allow a report to be filtered by adding filter strings to the Internet address. For the current release, this is not possible without trying to code this yourself.

    Kindest regards,

    Marco Mels

    Support Escalation Engineer Dynamics NAV

    These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.

Page 1 of 1 (7 items)