
So my project need to upload multiple notes/attachment using ribbon workbench -->Open HTML that can choose multiple attachments-->Then after selected few files simultaneously in browser then user need to click submit button to upload the attachments with text and field not compulsary...okay y'all may suggest http://scaleablesolutions.com/upload-notes-attachments-using-javascript-and-rest/ and yes I already try that but still not understand..can y'all crm community enlighten me please...so far my problem is fail to upload...All your help is much appreciated thank you..Below is my full coding:
<html><head>
<script type="text/javascript" src="../WebResources/ClientGlobalContext.js.aspx"></script>
<script type="text/javascript" src="../WebResource/" solution="" prefix"new_1sdk.rest.js"=""></script>
<title>Notes</title>
<meta><meta><meta><meta><meta></head><body style="word-wrap: break-word;"><p>Add Notes</p>
<input type="text" id="titleid" placeholder="Title:" style="margin-left:10px; margin-bottom:10px; width:60%">
<div>
<textarea name="textarea" placeholder="Description" style="margin-left:10px; margin-bottom:10px; width:60%" cols="40" rows="5" id="text"></textarea>
<div class="header">
<div class="contactheader">
<div align="left" style="margin-left:0px;margin-bottom:0px;margin-top:15px "> <label style=" font-size:14px;">Select Files to Upload</label></div>
<input type="file" id="datafile" name="files[]" multiple="true" value="" style="float:left;margin-left:0px;margin-top:0px; width: 380px">
<button type="button" id=" btnid " style="margin-left: 10px; color:Purple " onclick="save()">Create Notes</button>
<script type="text/javascript" language="javascript">
/* Note: Modify the ‘id’ and ‘nam’ variables according to your scenario, this is for the case if you are opening a custom web resource from an entity */
// Get Id and entity Name from the parent opener
var id = opener.parent.Xrm.Page.data.entity.getId();
var nam = opener.parent.Xrm.Page.data.entity.getEntityName();
function _arrayBufferToBase64(buffer) { // Convert Array Buffer to Base 64 string
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
// function for Creating note record using SDK REST
function createNote(title, description, docBody, fName, mType) {
var entity = {};
if (docBody != null & fName != null & mType != null) {
entity.DocumentBody = docBody;
entity.FileName = fName;
entity.MimeType = mType;
}
entity.Subject = title;
entity.NoteText = description;
entity.ObjectId = {
Id: id,
LogicalName: nam
};
SDK.REST.createRecord(
entity,
"Annotation",
function (result) {
var newEntityId = result.AnnotationId;
opener.RetrieveAnnotations(null);
window.close();
},
function (error) {
Xrm.Utility.alertDialog(error.message, null);
}
);
}
// function behind the onclick of Save button
function save() {
var file = document.getElementById("datafile").files[0];
var subject = document.getElementById("titleid").value;
var desc = document.getElementById("text").value;
if (file) {
var reader = new FileReader();
reader.onload = function (evt) {
var str = _arrayBufferToBase64(reader.result);
createNote(subject, desc, str, file.name, file.type);
}
reader.readAsArrayBuffer(file);
}
else {
createNote(subject, desc, null, null, null);
}
}
</script>
</div></div></div></body></html>
*This post is locked for comments
I have the same question (0)