Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Transferring BLOB data type over Web service using only C/AL code.

Posted on by 2

Hello All,

I have this customization to make where a BLOB data type (ie. any attachment file) to be sent from tenant database to master database within NAV. I can only use C/AL  code for sending data to master company from tenant company. I have managed to convert the attachment file to a BigText data but could not assign that BigText data to a published web service page field. Also, other data are being assigned to published page except for the attachment field. What am I missing here?

Below is the function I used for getting and setting the attachment file. Any help would be appreciated.

GetIssueAttachment(EntryNo_ : Integer;TenantID : Code[30];CompanyNameText : Text[30];AttachmentEncoding : BigText)
IssueAttachment.RESET;
IssueAttachment.SETRANGE("Tenant ID",TenantID);
IssueAttachment.SETRANGE("Entry No.",EntryNo_);
IssueAttachment.SETRANGE("Company Name","Company Name");
IF NOT IssueAttachment.FINDFIRST THEN
EXIT;

IssueAttachment.CALCFIELDS(Attachment);
IF NOT IssueAttachment.Attachment.HASVALUE THEN
EXIT;

IssueAttachment.Attachment.CREATEINSTREAM(IStream);
MemoryStream := MemoryStream.MemoryStream();
COPYSTREAM(MemoryStream, IStream);
bytes := MemoryStream.ToArray();
AttachmentEncoding.ADDTEXT(Convert.ToBase64String(bytes));

 

SetIssueAttachment(EntryNo : Integer;TenantID : Code[30];CompanyNameText : Text[30];lines : Text)
IssueAttachment.RESET;
IssueAttachment.SETRANGE("Tenant ID",TenantID);
IssueAttachment.SETRANGE("Entry No.",EntryNo);
IssueAttachment.SETRANGE("Company Name",CompanyNameText);
IF NOT IssueAttachment.FINDFIRST THEN
EXIT;

bytes := Convert.FromBase64String(AttachmentEncoding);
MemoryStream := MemoryStream.MemoryStream(bytes);
IssueAttachment.Attachment.CREATEOUTSTREAM(OutStr);
MemoryStream.WriteTo(OutStr);
IssueAttachment.MODIFY;

*This post is locked for comments

  • Sulav Thapaliya Profile Picture
    Sulav Thapaliya 2 on at
    RE: Transferring BLOB data type over Web service using only C/AL code.

    I want to send attachment like excel, word, pdf too using web service. So, your suggestion kind of works only for long text.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Transferring BLOB data type over Web service using only C/AL code.

    Hi,

    Have you tried testing the value of the bigtext variable like in the link or using the debugger?

    As far as publishing big text/blob data on a page you can do it by assigning the value on a new page variable using a function similar to your GetissueAttachment. You can view that functionality in page 42 "Sales Order" for field "Work Description" (assigned to var WorkDescription). I quickly confirmed it with SoapUI (for both text and bigtext variables) and it is another fast way to see if your functions work.

  • Sulav Thapaliya Profile Picture
    Sulav Thapaliya 2 on at
    RE: Transferring BLOB data type over Web service using only C/AL code.

    Hi Konstantinos,

    Actually , this is the function I was working on and the the bigtext variable gets value from getissueattachment function.

    SetIssueAttachment(EntryNo : Integer;TenantID : Code[30];CompanyNameText : Text[30];AttachmentEncoding : BigText)

    IssueAttachment.RESET;

    IssueAttachment.SETRANGE("Tenant ID",TenantID);

    IssueAttachment.SETRANGE("Entry No.",EntryNo);

    IssueAttachment.SETRANGE("Company Name",CompanyNameText);

    IF NOT IssueAttachment.FINDFIRST THEN

     EXIT;

    bytes := Convert.FromBase64String(AttachmentEncoding);

    MemoryStream := MemoryStream.MemoryStream(bytes);

    IssueAttachment.Attachment.CREATEOUTSTREAM(OutStr);

    MemoryStream.WriteTo(OutStr);

    IssueAttachment.MODIFY;

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Transferring BLOB data type over Web service using only C/AL code.

    Hi there,

    This might be a bit silly, but I don't see the bigtext variable AttachmentEncoding passed as a parameter in your SetIssueAttachment function - but a lines text param that's not being used. Are you using a global variable and assigning value to it beforehand?

    You've probably looked into this link www.kauffmann.nl/.../binary-data-with-nav-web-service while there's also a similar question on the forum that may be of help community.dynamics.com/.../205422.

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans