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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Creating sales order by code unit - SOAP service

(0) ShareShare
ReportReport
Posted on by 259

I am writing a codeunit which is published as a SOAP service. I am getting below error in my .net console app. I am using BC cloud sandbox

Microsoft.Dynamics.Nav.Runtime.NavInStream variable not initialized.

Here is my code unit

codeunit 50131 SalesOrderCodeUnit
{
trigger OnRun()
begin
end;

procedure Create(Base64Text: text)

var
base64Convert: codeunit "Base64 Convert";
doc: XmlDocument;
vConvertedContent: text;
varTempBlob: Codeunit "Temp Blob";
varInStream: InStream;
varOutStream: OutStream;
xmlNodeListParent: XmlNodeList;
element1: XmlElement;
salesOrderXML: Text;
xmlParentNode: XmlNode;
xmlChildNode: XmlNode;
i: integer;

// sales header
SalesHeader: Record "Sales Header";
Document_Type: Enum "Sales Document Type";
Sell_to_Customer_No: Code[20];
Sell_to_Customer_Name: Text[100];

begin
salesOrderXML := base64Convert.FromBase64(Base64Text);
varInStream.Read(salesOrderXML);
varTempBlob.CreateInStream(varInStream, TextEncoding::WINDOWS);
doc := XmlDocument.Create(varInStream);

doc.SelectNodes('//SalesOrders', xmlNodeListParent);
for i := 1 to xmlNodeListParent.Count do begin
if xmlNodeListParent.Get(i, xmlParentNode) then begin
SalesHeader.Init();
xmlParentNode.SelectSingleNode('//Sell_to_Customer_No', xmlChildNode);
Sell_to_Customer_No := xmlChildNode.AsXmlElement().InnerText;
xmlParentNode.SelectSingleNode('//Sell_to_Customer_Name', xmlChildNode);
Sell_to_Customer_Name := xmlChildNode.AsXmlElement().InnerText;
SalesHeader.Validate("Document Type", SalesHeader."Document Type"::Order);
SalesHeader.Validate("Sell-to Customer No.", Sell_to_Customer_No);
SalesHeader.Validate("Sell-to Customer Name", Sell_to_Customer_Name);
SalesHeader.Insert(true);
end;
end;

end;
}

I have the same question (0)
  • Suggested answer
    divyeshchitte Profile Picture
    970 on at

    HI,

    Outbound HTTP calls from extensions are blocked by default and must be approved for each extension

    To enable outbound HTTP calls, go to the Extension Management page in Business Central, and choose Configure. Then, on the Extension Settings page, make sure that Allow HttpClient Requests is selected. This setting must be enabled for each extension.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Here you're calling varInStream.Read(salesOrderXML) before instantiating the InStream object.

    varTempBlob.CreateInStream(varInStream, TextEncoding::WINDOWS) must appear before.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,033 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,105 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,035 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans