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;
}

  • 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,172 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 728 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 545 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 328 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans