04-11-2013 07:11 AM - edited 04-11-2013 07:21 AM
Hi, I don't know where exactly to post this question, as it's going to be an Outlook-AddIn working with SData.
Following situation:
we have a custom entity called license with an unique custom id ('TargetId'). The entity attachment has been extended with the property 'LicenseId'. Because we have to order these licenses externally we get an email every once in a while with the license files attached. The attached files names are including this 'TargetId' so it's not a problem to assign them to right license (entity).
The problem is to create a new attachment via SData (done) and link it to the custom entity since the payload of the SData Attachment System Endpoint does not include any custom properties.
This is how far I got until now: (note that this is just the code for testing)
// Creating an AtomEntry with a custom payload to provide some additional data
AtomEntry entAttachment = new AtomEntry(); SDataPayload plAttachment = new SDataPayload() { ResourceName = "Attachment", Namespace = "http://schemas.sage.com/slx/system/2010", Values = { { "LicenseId", "Q6UJ9A000O9M" }, { "attachDate", SyndicationDateTimeUtility.ParseRfc3339DateTime("2013-04-11T11:27:00+00:00") }, { "description", "VX1-Lizenz" }, { "dataType", "R" } } }; entAttachment.SetSDataPayload(plAttachment); try {
// This is basically the code from the Sage SalesLogix Endpoint Whitepaper 7.5.4 on PDF page 10 string filePath = @"c:\_Daten\Sage\TestDaten\12345678_DY3QC5F_0000_1.lic"; string contentType = MimeHelper.FindMimeType(filePath); string fileName = Path.GetFileName(filePath); FileStream stream = File.OpenRead(filePath); AttachedFile file = new AttachedFile(contentType, fileName, stream); RequestOperation operation = new RequestOperation(HttpMethod.Post, entAttachment) { Files = { file } }; SDataRequest request = new SDataRequest("http://q4de3gsy079.m1.sl-si.com:3333/sdata/slx/system/-/attachments", operation) { UserName = username, Password = password };
// This creates an attachment and uploads the file SDataResponse response = request.GetResponse();
// The following code is just used to verify the process AtomEntry responseEntry = (AtomEntry)response.Content; SDataPayload responsePayload; string text = string.Empty; responsePayload = responseEntry.GetSDataPayload(); foreach (KeyValuePair<string, object> dicEntry in responsePayload.Values) { text += string.Format("'{0}' : ", dicEntry.Key); if (dicEntry.Value != null) text += string.Format("'{0}'", dicEntry.Value); text += "\n"; } MessageBox.Show(text); } catch (Exception ex) { MessageBox.Show(ex.Message); }
The output of the MessageBox showing the variable 'text' is the following:
'attachDate' : '2013-04-11T11:27:00+00:00' 'dataType' : 'R' 'defectId' : 'description' : 'VX1-Lizenz' 'documentType' : 'fileName' : 12345678_DY3QC5F_0000_1.lic' 'physicalFileName' : '!Q6UJ9A0000GZ12345678_DY3QC5F_0000_1.lic' 'fileSize' : '760' 'accountId' : 'contactId' : 'contractId' : 'historyId' : 'leadId' : 'opportunityId' : 'productId' : 'returnId' : 'ticketId' : 'activityId' : 'salesOrderId' : 'createDate' : '2013-04-11T13:37:47+00:00' 'createUser' : 'ADMIN ' 'modifyDate' : '2013-04-11T13:37:47+00:00' 'modifyUser' : 'ADMIN '
As you can see, the custom property 'LicenseId' (along with some other custom properties) is missing. Also the 'AttachmentId' is not provided (why btw?)
I am aware of the possibility to extract the AttachmentId from the physicalFileName and then - using the Dynamic Endpoint - editing the attachment afterwards, but is there a possibility to do this all in one step?
I thought it may be possible to add custom properties to the Attachments System Endpoint. Although the sentence 'System endpoints are generated from a fixed API.' from the whitepaper diminishes my hope... Can anyone help me out?
Edit: We're using SLX 7.5.4.7144 (including HotFixes 1-16 and WebHotFixes 1-6)
Solved! Go to Solution.
04-22-2013 12:47 AM
01-23-2014 07:26 AM
can you please post your code? thx
04-04-2014 03:13 AM
Hi, took a while responding to your request, sry.
Here is the some code I'm using:
// OAttachment is a class from Microsoft.Office.Interop.Outlook
// This code has been taken from the source code of the SLX Desktop Manager version 7.5.4 and edited according to our needs
// 'this' is the class VX1ImportSDataClient which inherits the class SDataClient from the SLX Desktop Manager 7.5.4
public string CreateAttachment(OAttachment attachment) { AtomEntry creationEntry = new AtomEntry(); creationEntry.SetSDataPayload(new SDataPayload() { ResourceName = "Attachment", Namespace = "http://schemas.sage.com/slx/system/2010", Values = { { "attachDate", DateTime.UtcNow.ToUniversalTime().ToString("o") }, { "description", attachment.DisplayName }, { "dataType", "R" } } }); string contentType = MimeHelper.FindMimeType(attachment.FilePath); string fileName = this.ValidateFileName(attachment.DisplayName); FileStream fileStream = File.OpenRead(attachment.FilePath); AttachedFile attachedFile = new AttachedFile(contentType, fileName, fileStream); RequestOperation operation = new RequestOperation(HttpMethod.Post, creationEntry) { Files = { attachedFile } }; string uri = (new SDataUri(this.Server).AppendPath("sdata", "slx", "system", "-", "attachments")).ToString(); SDataRequest creationRequest = new SDataRequest(uri, operation) { UserName = this.UseWindowsAuth ? null : this.UserName, Password = this.UseWindowsAuth ? null : this.Password }; SDataPayload responsePayload = ((AtomEntry)creationRequest.GetResponse().Content).GetSDataPayload(); return responsePayload.Key; }
public void UpdateAttachment(string attachmentId, string licenseId, string salesorderId, string accountId, string contactId) { SDataSingleResourceRequest updateRequest = new SDataSingleResourceRequest(NewSDataService()); updateRequest.ResourceKind = "Attachments"; updateRequest.ResourceSelector = string.Format("'{0}'", attachmentId); AtomEntry updateEntry = updateRequest.Read(); SDataPayload updatePayload = updateEntry.GetSDataPayload(); if (!string.IsNullOrEmpty(licenseId)) updatePayload.Values["LicenseId"] = licenseId; if (!string.IsNullOrEmpty(salesorderId)) updatePayload.Values["SalesorderId"] = salesorderId; if (!string.IsNullOrEmpty(accountId)) updatePayload.Values["AccountId"] = accountId; if (!string.IsNullOrEmpty(contactId)) updatePayload.Values["ContactId"] = contactId; updateEntry.SetSDataPayload(updatePayload); updateRequest.Entry = updateEntry; updateRequest.Update(); }