Skip to main content

Notifications

Announcements

No record found.

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

Irn generation issue in bussines central

(0) ShareShare
ReportReport
Posted on by 73

Hello All, I have created below function to generate IRN for BC cloud India localization. there is standard codeunit 1297(Http Web Request Mgt.) in business BUT its has scope of 'Onprem'.I have used 'HttpRequestMessage' dotnet variable but its giving me different result. Is there any way to handle http web request in business central cloud ?

 procedure GenerateIRN(user_name: Text; password: Text; gstin: Code[15]; Authorization: Text; SalInvHdr: Record "Sales Invoice Header")
    var
   
        IRNHttpWebRequestMgt: HttpRequestMessage;
        IRNPostUrl: Text;
        contentHeaders: HttpHeaders;
        content: HttpContent;
        SInvNo: Text;
        FilePath: Text;
        FileName: Text;
        IRNApiResult: Text;
        IRNTempBlob: Codeunit "Temp Blob";
        IRNInstr: InStream;
        IRNResponseHeaders: HttpResponseMessage;
        HttpResponse: HttpResponseMessage;
        httpClient1: HttpClient;
        
    begin
       
        IRNPostUrl := 'xyz.com/.../invoice';


        content.GetHeaders(contentHeaders);
        contentHeaders.Clear();
        contentHeaders.Add('Content-Type''application/json');
        contentHeaders.Add('user_name', user_name);
        contentHeaders.Add('password', password);
        contentHeaders.Add('gstin', gstin);
        contentHeaders.Add('requestid', GenerateReqId);
        contentHeaders.Add('Authorization', Authorization);
        //contentHeaders.Add()
        //IRNHttpWebRequestMgt.Method.

        // IRNHttpWebRequestMgt.Initialize(IRNPostUrl);

        // IRNHttpWebRequestMgt.DisableUI;

        IRNHttpWebRequestMgt.Content := content;

        IRNHttpWebRequestMgt.SetRequestUri(IRNPostUrl);
        IRNHttpWebRequestMgt.Method := 'POST';
        GenerateJsonPayload(SalInvHdr);

        SInvNo := CONVERTSTR(SalInvHdr."No."'/''_');
        //FilePath := 'C:\Users\jitendra\Desktop\E- Invoice\Json\';
        FilePath := 'C:\EinvJson\';
        FileName := SInvNo + '.txt';



        IRNTempBlob.CREATEINSTREAM(IRNInstr);
        httpClient1.Post(IRNPostUrl, content, HttpResponse);

        // IF IRNHttpWebRequestMgt.GetResponse(IRNInstr, IRNHttpStatusCode, IRNResponseHeaders) THEN BEGIN

        //     // MESSAGE('httpstatuscode : '+AuthHttpStatusCode.ToString);

        //     // MESSAGE(AuthResponseHeaders.ToString);

        //     IRNApiResult := IRNTempBlob.ReadAsText('', TEXTENCODING::UTF8);

        //     IF IRNApiResult <> '' THEN BEGIN
        //     end;
        //     end;
    end;
  • Suggested answer
    NAV_with_Narang Profile Picture
    NAV_with_Narang 2,236 Super User 2024 Season 1 on at
    RE: Irn generation issue in bussines central

    Yes, DotNet won't work in BC SaaS. You'll have to use the inbuilt JSON variables

    Check this link to get started

    www.youtube.com/watch

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans