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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

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

(0) ShareShare
ReportReport
Posted on by 12

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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • Sulav Thapaliya Profile Picture
    12 on at

    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
    on at

    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
    12 on at

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

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

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 > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans