Sharepoint 2010 CAML-Query, Retrieve the description of an column - javascript

Is it possible to retrieve the column description data by using an CAML-Query in javascript?

How to retrieve site column metadata (eg. description) via CSOM (JavaScript)
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var fields = web.get_fields();
var field = fields.getByTitle('Workflow Name');
ctx.load(field);
ctx.executeQueryAsync(
function() {
console.log('Description:' + field.get_description());
},
function(sender,args) {
console.log('An error occured: ' + args.get_message());
}
);

Related

how to calculate the size of a folder google script with google picker api

Yo,
I would like to create a script where the user can choose a folder and then by getting the id of the folder I display the size of the folder.
I manage to retrieve the ID but I don't know how from this id I can calculate the size and display it.
here is the code to show the picker google drive :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script type="text/javascript">
var DIALOG_DIMENSIONS = {
width: 600,
height: 425
};
var pickerApiLoaded = false;
function onApiLoad() {
gapi.load('picker', {
'callback': function() {
pickerApiLoaded = true;
}
});
google.script.run.withSuccessHandler(createPicker)
.withFailureHandler(showError).getOAuthToken();
}
function createPicker(token) {
if (pickerApiLoaded && token) {
var docsView = new google.picker.DocsView()
.setIncludeFolders(true)
.setMimeTypes('application/vnd.google-apps.folder')
.setSelectFolderEnabled(true);
var picker = new google.picker.PickerBuilder()
.addView(docsView)
.enableFeature(google.picker.Feature.NAV_HIDDEN)
.hideTitleBar()
.setSize(DIALOG_DIMENSIONS.width - 2, DIALOG_DIMENSIONS.height - 2)
.setOAuthToken(token)
.setCallback(pickerCallback)
.setOrigin('https://docs.google.com')
.build();
picker.setVisible(true);
} else {
showError('Unable to load the file picker.');
}
}
/**
* A callback function that extracts the chosen document's metadata from the
* response object. For details on the response object, see
* https://developers.google.com/picker/docs/result
*
* #param {object} data The response object.
*/
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = doc[google.picker.Document.ID];
// Show the ID of the Google Drive folder
document.getElementById('result').innerHTML = id;
} else if (action == google.picker.Action.CANCEL) {
google.script.host.close();
}
}
function showError(message) {
document.getElementById('result').innerHTML = 'Error: ' + message;
}
</script>
</head>
<body>
<div>
<p id='result'></p>
</div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</body>
</html>
function onOpen() {
SpreadsheetApp.getUi().createMenu('Google Picker')
.addItem('Choose Folder', 'showPicker')
.addToUi();
}
/**
* Displays an HTML-service dialog in Google Sheets that contains client-side
* JavaScript code for the Google Picker API.
*/
function showPicker() {
var html = HtmlService.createHtmlOutputFromFile('Picker.html')
.setWidth(600)
.setHeight(425)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Select Folder');
}
function getOAuthToken() {
DriveApp.getRootFolder();
return ScriptApp.getOAuthToken();
}
I would like to merge the two code.gs file with the id of picker.html
function test(){
var root = DriveApp.getFolderById("1fl7XeqwelnlJJnSQjjvDmdxYudfCwQAR");
var list = [];
var list = recurseFolder(root, list);
//Logger.log(JSON.stringify(list));
//This is just how I am testing the outputed list. You can do what you need.
var sheet = SpreadsheetApp.getActiveSheet();
//list.forEach(function (row){
// sheet.appendRow(row);
//});
Logger.log("test !\n")
}
var fileCounter = folderCounter = fileSize = 0;
function recurseFolder(folder, list){
var files = folder.getFiles();
var subfolders = folder.getFolders();
while (files.hasNext()){ //add all the files to our list first.
var file = files.next();
var row = [];
fileCounter++;
fileSize+=file.getSize();
//Logger.log("File: " + folder.getName());
//row.push(folder.getName(),file.getName(),file.getId(),file.getUrl(),file.getSize(),file.getDateCreated(),file.getLastUpdated())
//list.push(row);
}
while (subfolders.hasNext()){ //Recurse through child folders.
subfolder = subfolders.next();
folderCounter++;
//Logger.log("Folder: " + subfolder.getName());
list = recurseFolder(subfolder, list); //Past the original list in so it stays a 2D Array suitible for inserting into a range.
}
Logger.log ("file : " + fileCounter + " folderCounter : " + folderCounter + " fileSize : " + fileSize);
}
You can use gapi to use the Drive API and use it to do the exact same logic as you did in Apps Script. You can read the official quickstart and modify it to query the size of files instead of simply listing the names.
Note that you'll have to load auth, client, and picker. Also you'll have to integrate the picker with it.
References
The Google Picker API (Picker API guide)
JavaScript (Browser) Quickstart (Google Drive API guide)
Files: get (Google Drive API reference)
Files resource (Google Drive API reference)

Retrieve email from People or Group Field

I have People or Group Field
Normally I retrieve value of fields as:
var fieldUsuario = ctx.CurrentItem.Notificar_x0020_a
But now I dont want text value, I debbug it and it have email in span as:
<span class="ms-entity-resolved" id="Notificar_x0020_a_084ffd45-b361-458e-b55f-c824ba8995ec_$ClientPeoplePicker_i:0#.f|membership|email#mydomain.com_ProcessedUser0_UserDisplay" title="User, SubName" style="max-width: 331px;">User, SubName</span>
As you can see it have: email#mydomain.com I want to retrieve this value. How can I achieve it? Regards
You may try this.
<script type="text/javascript">
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function (){
var clientContext = new SP.ClientContext.get_current();
var oWeb = clientContext.get_web();
var list = oWeb.get_lists().getByTitle('PeopleFieldTest');
var item = list.getItemById(1);
clientContext.load(item);
clientContext.executeQueryAsync(function (sender, args) {
var userEmail = item.get_item("Notificar").get_email();//replace Notificar with your person column
alert(userEmail);
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
});
</script>

How to display image stored in variable using the url?

USING PARSE.COM AND THE JAVASCRIPT SDK
With the below code I can get as far as letting the user upload an image from the webpage and storing that as an object in a "file" column in the parse db.
I can store the image details, including the url in the
What i'm unable to do is extract the url back out and display the image on a html page.
I've added the screen shots to show how the data is held in var profilePhoto but i'm then unable to make it show on the page using $("profile_pic").attr('src',jobApplication[0]);
What have I overlooked ? I've searched SO and cannot find an relevant question that helps with this.
RESULTS IN INSPECT ELEMENT
Arguments[1]0: t.Filecallee: function () {length: 1__proto__: Object user_profile.html:408
t.File {_name: "tfss-fe809632-ffb8-445c-99f3-1149e4ffdec5-IMG_0047.jpg", _source:
t.Promise, _previousSave: t.Promise, _url:
"http://files.parsetfss.com/0fc5cba8-caf7-4c81-aafc…fe809632-ffb8-445c-99f3-1149e4ffdec5-IMG_0047.jpg",
name: function…}_name:
"tfss-fe809632-ffb8-445c-99f3-1149e4ffdec5-IMG_0047.jpg"_previousSave:
t.Promise_source: t.Promise_url:
"http://files.parsetfss.com/0fc5cba8-caf7-4c81-aafc-36390888e497/tfss-fe809632-ffb8-445c-99f3-1149e4ffdec5-IMG_0047.jpg"proto:
Object
CODE
$(document).ready(function() {
var parseAPPID = "XXX";
var parseJSID = "XXXX";
//Initialize Parse
Parse.initialize(parseAPPID,parseJSID);
$("#fileUploadBtn").on("click", function(e) {
var fileUploadControl = $("#fileUploader")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = file.name;
console.log("here goes nothing...");
var parseFile = new Parse.File(name, file);
parseFile.save().then(function() {
console.log("Woot!");
console.dir(arguments);
var User = Parse.Object.extend("_User")
var jobApplication = Parse.User.current();
jobApplication.set("ProfilePic", parseFile);
jobApplication.save();
var profilePhoto = jobApplication.get("ProfilePic");
console.log(profilePhoto);
$("profile_pic").attr('src',jobApplication[0]);
}, function(error) {
console.log("Error");
console.dir(error);
});
}
});
});
$("profile_pic") returns elements with profile_pic tag name, which obviously is not the thing you need. Don't see your HTML, but if profile_pic is id or class name of your img element, this will work if you type $("#profile_pic") or $(".profile_pic") respectively.

Setting Search Center URL in SharePoint 2013 using Javascript CSOM

In SharePoint 2013, I am trying to access Search object through JavaScript CSOM.
I want to know the object which can give me the access to Search Settings under Site Settings.
I tried looking under SP object but I didn't find any Search related object there.
My goal is to change the search Center URL through JavaScript CSOM.
Thanks in Advance!!!
How to set Search Settings in SharePoint 2013 via CSOM
function updateSearchSettings(searchSenterUrl,resultsPageUrl,Success,Error) {
var context = SP.ClientContext.get_current();
var web = context.get_site().get_rootWeb();
var props = web.get_allProperties();
props.set_item("SRCH_ENH_FTR_URL_SITE",searchSenterUrl);
props.set_item("SRCH_SB_SET_SITE",JSON.stringify({"Inherit":false,"ResultsPageAddress":resultsPageUrl,"ShowNavigation":false}));
web.update();
context.load(props);
context.executeQueryAsync(
function () {
var searchCenterUrl = props.get_item("SRCH_ENH_FTR_URL_SITE");
var searchPageProps = JSON.parse(props.get_item("SRCH_SB_SET_SITE"));
Success(searchCenterUrl,searchPageProps);
},
Error
);
}
//Usage
updateSearchSettings("/sites/search/pages2","/sites/search/pages/default.aspx",function(searchCenterUrl,searchPageProps){
console.log('Search Center Url:' + searchCenterUrl);
console.log('Results Page Url:' + searchPageProps.ResultsPageAddress);
},
function (sender, args) {
console.log("Error: " + args.get_message());
});
The search centre URL for a given web is stored in the Property bag for that web, on the RootWeb you can also set the search centre URL for the site.
In 2013 the keys have changed from 2010, they are now SRCH_ENH_FTR_URL_WEB and SRCH_ENH_FTR_URL_SITE respectivly.
The code to set them is something like this:
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_site().get_rootWeb();
var props = web.get_allProperties();
props.set_item("SRCH_ENH_FTR_URL_SITE","/sites/search/pages");
web.update();
ctx.load(web);
ctx.executeQueryAsync(function () {
alert("Search Settings Modified");
},
function() {
alert("failed");
});

Create a copy of document in SharePoint 2010 document library using JavaScript

I want to create a copy of document in the SharePoint document library.
Basically let us assume there is a template and every user will open the document by clicking on it. I want to create a copy of file user has clicked and open that file for editting.
I have tried using JavaScript Client Object model of SharePoint. But the examples are for manipulating list items but not for document library.
Can any one please point to any sources that I can use to manipulate the files in document library
One restriction being I need to use JavaScript object model or web services to achive this functionality. i.e., NO server side code
Following is the code I got till now
The approach I am planning to use is copy the existing file object
Rename it and
Save it to other document library
Please ignore formatting as I am not able to do it properly and this is under development code
<script type="text/javascript">
var clientContext = null;
var web = null;
var meetingItems = null;
var filePath = null;
var file = null;
debugger;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize() {
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle("Documents");
clientContext.load(list, 'Title', 'Id');
var queryStart = "<View>"+ "<Query>"+ "<Where>"+ "<Eq>"+ "<FieldRef Name='Title'/>" + "<Value Type='Text'>";
var queryEnd = "</Value>"+ "</Eq>"+ "</Where>"+ "</Query>"+ "</View>";
camlQuery = new SP.CamlQuery();
queryMeeting = queryStart + 'DevCookbook'+ queryEnd;
camlQuery.set_viewXml(queryMeeting);
meetingItems = list.getItems(camlQuery);
clientContext.load(meetingItems);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onListLoadSuccess(sender, args) {
filePath = meetingItems.get_item(0).get_path();
file = meetingItems.get_item(0);
debugger;
clientContext.load(file);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onFileLoadSuccess), Function.createDelegate(this, this.onFileFailed));
// alert("List title : " + this.list.get_title() + "; List ID : " + this.list.get_id());
// doclist();
}
function doclist()
{
var path = file.get_title();
path = meetingItems.get_item(0).get_file().get_title();
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
function onFileLoadSuccess(sender, args) {
debugger;
alert("List title : " + this.list.get_title() + "; List ID : " + this.list.get_id());
}
function onFileFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
I used copy webservice to do the functionality.
Approach is combination of Object Model and JavaScript functions
Copy the file from templates library.
Check out file using "CheckoutDocument" function
Add metadata in background
Show edits metadata pop up to user using
var oDialog = {
url: "../Library/Forms/Edit.aspx?ID=" + itemID,
title: "Create a new document"
};
SP.UI.ModalDialog.showModalDialog(oDialog)
After user input check in the document

Categories

Resources