This is a tough one for me to ask because I'm not getting any errors anymore. But the process doesn't work. I'll do my best to explain.
I create a working CrmServiceClient object. I know it works because I can run queries through it successfully. I use the "CreateAnnotation" method on that connection object with the intention of attaching a file to a specific account. The parameters for the method call...
- string targetEntityTypeName: set to "account"
- Guid targetEntityId: set to the Guid of the account that I looked up. I've verified that it's the right value
- Dictionary<string, CrmDataTypeWrapper> fieldList: set to a dictionary I build based on values I get from the file I'm testing with. I've tried a few combinations of the following list of dictionary entries...
- key: "filename" / value: "testfile.docx" (string)
- key: "mimetype" / value: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" (string)
- key: "filesize" / value: (an integer matching the file size in bytes, sometimes skipped in my testing)
- key: "documentbody" / value: (a string representation of the byte array because it wouldn't accept the byte array)
- key: "subject" / value: "Data Migration File Test" (string)
- key: "notetext" / value: "This file was migrated from the old CRM instance during our consolidation effort" (string)
- key: "isdocument" / value: true (boolean, sometimes skipped in my testing)
The return value of the method is a Guid for the newly created Note. What I get back is the empty GUID (Guid.empty, or all zeroes). And when I look in our sandbox at the account, there's no new note. I've verified that my connection in my code is to the same sandbox. I've verified that the account I'm using has the ability to add a note (by manually adding a note with an attached file). And oddly enough in the "OneNote" tab of the Account page, I can see that I had some activity, though I don't know how that might be related. When I run the code, it executes without exception, and just comes back with that empty GUID, and there's no new note on the account.
I'm realizing that the first question here is going to be for me to post the code. Here goes... I'll try to trim it to just what's relevant...
Getting the File data...
FileName = Path.GetFileName(SourceFilePath); string fileExt = Path.GetExtension(SourceFilePath); FileMimeType = FileUtility.GetMimeType(fileExt); //utility method I wrote to get the mime type FileSizeInBytesLong = new FileInfo(SourceFilePath).Length; FileContents = File.ReadAllBytes(SourceFilePath);
Build the dictionary to be used in the method call...
retVal.Add(FileNameKV.Key, new CrmDataTypeWrapper(FileNameKV.Value, CrmFieldType.String)); retVal.Add(FileMimeTypeKV.Key, new CrmDataTypeWrapper(FileMimeTypeKV.Value, CrmFieldType.String)); //retVal.Add(FileSizeInBytesKV.Key, new CrmDataTypeWrapper(FileSizeInBytesKV.Value, CrmFieldType.CrmNumber)); retVal.Add(FileContentsStringKV.Key, new CrmDataTypeWrapper(FileContentsStringKV.Value, CrmFieldType.String)); //retVal.Add(IsDocumentKV.Key, new CrmDataTypeWrapper(IsDocumentKV.Value, CrmFieldType.CrmBoolean)); if (!string.IsNullOrEmpty(SubjectLine)) { retVal.Add(SubjectLineKV.Key, new CrmDataTypeWrapper(SubjectLineKV.Value, CrmFieldType.String)); } else { retVal.Add(SubjectLineKV.Key, new CrmDataTypeWrapper("File Attachment", CrmFieldType.String)); } //required field if (!string.IsNullOrEmpty(Description)) { retVal.Add(DescriptionKV.Key, new CrmDataTypeWrapper(DescriptionKV.Value, CrmFieldType.String)); } else { retVal.Add(DescriptionKV.Key, new CrmDataTypeWrapper("File Attachment from migration process", CrmFieldType.String)); }
File info...
It's a Docx file that's 298K
The Question...
So what are some of the possible explanations for why the "CreateAnnotation" method would fail in this way? What would stop the note from being added?
*This post is locked for comments