Closed nick-webbgh closed 4 years ago
Hi, @nick-webbgh
At the moment, I am focused on improving the Connected service by Microsoft and actively contribute to it, since its development has resumed. All features will be transferred to this project. In addition, it is developing faster, so all new features will be added there.
You can create your issues in this repository.
I'm trying to add a Document Attachment record via an Unchase Connected Service to a Microsoft Dynamics NAV database in C# (Visual Studio 2019). I downloaded the XML metadata from a Dynamics NAV URL. In Visual Studio, I perform an Add / Update Unchase Connected Service and pointed it at the metadata file. This process auto-generates a Reference.cs code-file. I then call the appropriate objects / properties / methods (see code below):-
private NAV.NAV gobjDSC; // DataServiceContext
const int SHTABLEID = 5900; string lstrFileName = @"C:\Test\Test Attachment 3.pdf"; System.IO.FileInfo lfi = new System.IO.FileInfo(lstrFileName); NAV.API_Document_Attachment lobjDA = NAV.API_Document_Attachment.CreateAPI_Document_Attachment(SHTABLEID, "SO000006", "Order", 0, 1); lobjDA.AttachedDate = DateTime.Now; lobjDA.FileName = lfi.Name; lobjDA.FileExtension = lfi.Extension.Replace(".", string.Empty); lobjDA.FileType = "2"; FileStream lobjFS = new FileStream(lstrFileName, FileMode.Open); var ms = new MemoryStream(); lobjFS.CopyTo(ms); System.Guid lobjGuid = System.Guid.NewGuid(); lobjDA.DocumentReferenceID = NAV.Media.CreateMedia(lobjGuid); gobjDSC.AddToAPI_Document_Attachment(lobjDA);
gobjDSC.SetSaveStream(lobjDA.DocumentReferenceID.Content, ms, true, new DataServiceRequestArgs { ContentType = "application/pdf" }); // ERROR
gobjDSC.SaveChanges();
The SetSaveStream line of code above produces the error: 'Value cannot be null. Parameter name: entity' Sure enough the Content property is null. As the Content property is of type: DataServiceStreamLink and there doesn't appear to be a way of instantiating it in the conventional way (e.g.) lobjDA.DocumentReferenceID.Content = new DataServiceStreamLink(); error CS1729: 'DataServiceStreamLink' does not contain a constructor that takes 0 arguments … I'm stuck in a stalemate. It was my understanding that SetSaveStream would assign a value to: lobjDA.DocumentReferenceID.Content but it is objecting to it being null? (Chicken and Egg) Any thoughts? Thanks in advance for any support given.