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");
});
Related
I have an external list in SharePoint that includes a URL column. The URL column is a calculated field in SQL server, so the entire URL is already there. I need this field to hyperlink and I have been trying to use JSLink to do so. What would the JavaScript for that look like?
For example, if my fields were...
First Name | Last Name | Profile URL
How would I get the URL in the Profile URL field to hyperlink?
I have been looking for solutions all morning without any luck. I am not familiar with JavaScript, so the code I am using is pieced together from posts I have been reading. I have made sure the my JSLink address is correct.
~site/SiteAssets/myCode.js
I have tried different variations of code. My latest is this:
(function () {
var profUrlField = {};
profUrlField.Templates = {};
profUrlField.Templates.Fields = {
"Profile_X0020_URL": {
"View": function (ctx) {
var urlField = ctx.CurrentItem[ctx.CurrentFieldSchema["Profile_X0020_URL"]];
return "<a href='" + urlField + "'>" + urlField + "</a>";
}
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(profileUrlField);
})();
After applying my JSLink to my web part I reload the page and nothing happens. No errors but no links.
I'm also not sure how to reference the column. In SQL Server it is PROFILE_URL, but in the SharePoint list header it is Profile URL.
Modify the code as below to check if it works.
(function () {
var profUrlField = {};
profUrlField.Templates = {};
profUrlField.Templates.Fields = {
"PROFILE_URL": {
"View": function (ctx) {
var urlField = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
return "<a href='" + urlField + "'>" + urlField + "</a>";
}
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(profileUrlField);
})();
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.
I have google custom search box (Javascript) in my website.
with following code:
<script type="text/javascript">
var searchTerm = "";
google.load('search', '1', { language: 'en' });
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('XXXXX');
customSearchControl.draw('cse');
customSearchControl.execute('<%= Request.QueryString["search"] %>');
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
}, true);
</script>
When user clicks on one of the results and on the target page clicks on Browser's back button, an empty search screen appears.
Is it possible to keep the results page when getting back to the search page?
Also I would like to retrieve the search term from this script, how can I do that?
Thanks in advance
This is the API of google CSE:
https://developers.google.com/custom-search/docs/js/cselement-devguide
Here you can see a custom query working:
https://code.google.com/apis/ajax/playground/#custom_search_control
and this is how you retrieve the query:
https://code.google.com/apis/ajax/playground/#show_search_query
Using rafael's suggestion I came with following solution for my problem:
<script type="text/javascript">
var searchTerm = "";
if (sessionStorage.getItem("googleSearchTerm") != '')
searchTerm = sessionStorage.getItem("googleSearchTerm");
runGoogleSearch(searchTerm);
function runGoogleSearch(searchTerm) {
google.load('search', '1', { language: 'en' });
google.setOnLoadCallback(function () {
var customSearchControl = new google.search.CustomSearchControl('XXXXXX');
customSearchControl.draw('cse');
customSearchControl.execute(searchTerm);
// Set a callback so that whenever a search is started we will call searchStart
customSearchControl.setSearchStartingCallback(this, searchStart);
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
}, true);
}
// Whenever a search starts, alert the query.
function searchStart(searchControl, searcher, query) {
sessionStorage.setItem("googleSearchTerm", "");
var content = document.getElementById('content');
var queryDiv = document.getElementById('query');
if (!queryDiv) {
var queryDiv = document.createElement('div');
queryDiv.id = 'query';
document.body.appendChild(queryDiv);
}
//queryDiv.innerHTML = "User searched for: " + query;
sessionStorage.setItem("googleSearchTerm", query);
//alert(sessionStorage.getItem("googleSearchTerm") + " gozo");
}
</script>
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());
}
);
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