Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.

(1) ShareShare
ReportReport
Posted on by 153
Hi Guys,
 
I am facing this error.
Error: Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.Runtime.NavJsonObject.
Is any way to solve this problem.
 
  • Suggested answer
    Dharmendra_Chavda Profile Picture
    Dharmendra_Chavda 256 on at
    Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.
    I deserialize the JSON file into a JSON token, and then into an array and object.
     
     
    local procedure ShippingAddress(ResponseText: Text)
        var
            JToken: JsonToken;
            JLinesToken: JsonToken;
            JObject: JsonObject;
            ValueObject: JsonObject;
            Jarray: JsonArray;
            i: Integer;
        begin
            JToken.ReadFrom(ResponseText);
            JObject := JToken.AsObject();
            if JObject.SelectToken('$.value', JLinesToken) then begin
                Jarray := JLinesToken.AsArray();
                for i := 0 TO (Jarray.Count - 1) do begin
                    Jarray.Get(i, JLinesToken);
                    ValueObject := JLinesToken.AsObject();
                    SetShipping(ValueObject); //Create Shipping Address
                end;
            end else begin
                SetShipping(JObject);
            end;
        end;
  • KK-20050817-0 Profile Picture
    KK-20050817-0 54 on at
    Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.
     // Iterate over attributes to find currency and rate
                            for i := 1 to xmlAttrCol.Count do begin
                                if xmlAttrCol.Get(i, xmlAttr) then begin
                                    // GPT comment: xmlAttr is initialized from xmlAttrCol.Get(i, xmlAttr)
     
                                    // Check for 'currency' attribute
                                    if xmlAttr.Name = 'currency' then
                                        TargetCurrency := xmlAttr.Value;
     
                                    // Check for 'rate' attribute
                                    if xmlAttr.Name = 'rate' then
                                        if Evaluate(Rate, xmlAttr.Value) then begin
                                            // Check if the target currency is one of our desired target currencies
                                            if TargetCurrencies.Contains(TargetCurrency) then begin
                                                // Insert or update the exchange rate in Currency Exchange Rate table
                                                if CurrencyExchangeRate.Get('EUR', TargetCurrency, Today) then begin
                                                    CurrencyExchangeRate.Validate("Exchange Rate Amount", Rate);
                                                    CurrencyExchangeRate.Modify();
                                                end else begin
                                                    CurrencyExchangeRate.Init();
                                                    CurrencyExchangeRate.Validate("Currency Code", TargetCurrency);
                                                    CurrencyExchangeRate.Validate("Starting Date", Today);
                                                    CurrencyExchangeRate.Validate("Exchange Rate Amount", Rate);
                                                    CurrencyExchangeRate.Insert();
                                                end;
                                                Message('I m inside 2 cu');
                                            end;
                                        end else
                                            Error('Failed to convert rate for %1', TargetCurrency);
                                end;
                            end;
                            XmlElement := gXmlNode.AsXmlElement(); // GPT comment: Initialize XmlElement from gXmlNode
                        end;
  • Inge M. Bruvik Profile Picture
    Inge M. Bruvik 995 Super User 2024 Season 1 on at
    Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.
    Maybe you can share the code that is failing?
    I belive it will be easier to assist you if we can have a look at your code.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans