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

Notifications

Announcements

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
    968 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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,594

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,594

#3
YUN ZHU Profile Picture

YUN ZHU 748 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans