Skip to content

Instantly share code, notes, and snippets.

spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items(" + id + ")/AttachmentFiles/add(FileName='" + file.name + "')",
function uploadFile(listName, id, file) {
var deferred = $.Deferred();
var fileName = file.name;
getFileBuffer(file).then(
function (buffer) {
var bytes = new Uint8Array(buffer);
var binary = '';
for (var b = 0; b < bytes.length; b++) {
binary += String.fromCharCode(bytes[b]);
}
function loopFileUpload(listName, id, listValues, fileCountCheck) {
var dfd = $.Deferred();
uploadFile(listName, id, listValues[0].Files[fileCountCheck].Attachment).then(
function (data) {
var objcontext = new SP.ClientContext();
var targetList = objcontext.get_web().get_lists().getByTitle(listName);
var listItem = targetList.getItemById(id);
objcontext.load(listItem);
objcontext.executeQueryAsync(function () {
console.log("Reload List Item- Success");
var createItemWithAttachments = function(listName, listValues){
var fileCountCheck = 0;
var fileNames;
var context = new SP.ClientContext.get_current();
var dfd = $.Deferred();
var targetList = context.get_web().get_lists().getByTitle(listName);
context.load(targetList);
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = targetList.addItem(itemCreateInfo);
listItem.set_item("FirstName", listValues[0].FirstName);
$("#attachFilesContainer input:file").each(function () {
if ($(this)[0].files[0]) {
fileArray.push({ "Attachment": $(this)[0].files[0] });
}
});
$(function () {
var fileCountCheck = 0;
$("#btnSubmit").click(function () {
var data = [];
var fileArray = [];
$("#attachFilesContainer input:file").each(function () {
if ($(this)[0].files[0]) {
fileArray.push({ "Attachment": $(this)[0].files[0] });
}
});
<div class="fld">
<div>
<span>First Name</span>
<span><input type="text" id="txtFirstName"></span>
</div>
<div>
<span>Last Name</span>
<span><input type="text" id="txtLastName"></span>
</div>
function changePermissionLink(ctx){
var fieldValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
var siteUrl = ctx.CurrentItem.SiteURL;
var permissionUrl = $(siteUrl).html()+"/_layouts/15/user.aspx"
var permissionLink = '<a href='+permissionUrl+' target="_blank"/>Permission</a>'
return permissionLink;
}
@premchandpl
premchandpl / jqueryreference.js
Created August 11, 2014 20:26
Adding jquery references dynamically
function LoadResources() {
if (typeof (jQuery) == "undefined") {
var script = document.createElement("script")
script.type = "text/javascript";
script.src = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
}
}