Tampilkan postingan dengan label jQuery. Tampilkan semua postingan
Tampilkan postingan dengan label jQuery. Tampilkan semua postingan

3 Apr 2017

SharePoint CAML Query through jQuery

I was just digging into my code snippet, and I thought this worth to share. I got the sample code where we can query using CAML in jQuery.

After a few tests, it’s still valid to be used. Here it is!


var DocLibName = "Shared Documents";
var camlQry = 
	"<View Scope='RecursiveAll'>" +
		"<Query>" +
			"<Where>" +
				"<And>" +
					"<Leq>" +
						"<FieldRef Name='Created'/>" +
						"<Value Type='DateTime'><Today /></Value>" +
					"</Leq>" +
					"<Eq>" +
						"<FieldRef Name='FSObjType'/>" +
						"<Value Type='Integer'>0</Value>" +
					"</Eq>" +
				"</And>" + 
			"</Where>" +
		"</Query>" +
	"</View>";
var requestData = { "query" :
	{ "__metadata" :
		{ "type" : "SP.CamlQuery" },
		"ViewXml" : camlQry
	}
};
$.ajax({
	url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + DocLibName + "')/GetItems?$expand=FieldValuesAsText",
	method: "POST",
	async: false,
	data: JSON.stringify(requestData),
	headers: {
		"X-RequestDigest": $("#__REQUESTDIGEST").val(),
		"Accept": "application/json; odata=verbose",
		"Content-Type": "application/json; odata=verbose"
	},
	success : function(d) {
		$.each(d.d.results, function (iRow, vRow) {
			//do your own processing here
		});
	}, error : function(a, b, c) {
		console.log(a);
		console.log(b);
		console.log(c);
	}
});

Enjoy!

19 Agu 2016

Simple Workaround for Content Editor Webpart in Another Site Collection

Guess what? You have created a HTML script stored somewhere in SharePoint, and you want to use it somewhere in another Site Collection. But you are stuck with this error, “Cannot retrieve the URL specified in the Content Link property. For more assistance, contact your site administrator”.

image

There are a few workarounds you can try.

Using Page Viewer or IFRAME

To use the page viewer, the solution is quite straight-forward and can be described in a few sentences.

Firstly, you know that you have created the HTML script, now create a page in the same Site Collection, then add Content Editor Webpart that links to the HTML script.

Then you can go to the other Site Collection, create a page with Page Viewer, or direct HTML with IFRAME which links to the page created in previous step. Remember, the SharePoint top links bar and left navigation will still be displayed. To overcome that, you can add query string “IsDlg=1” at the end of the URL.

If your URL is like: http://contoso.com/Pages/cewp.aspx, then it should be like http://contoso.com/Pages/cewp.aspx?IsDlg=1.

Using jQuery

If your masterpage is attached with jQuery, you can re-use the following code.

<div class="pp-container">
</div>
<script type="text/javascript">
 $.ajax({
  url: "/SiteAssets/common/thescripts.txt",
  method: "GET",
  success: function (data) {
   $('div.pp-container').append(data);
  },
  error: function (data) {
   console.log("Error:");
   console.log(data);
  }
 });
</script>

Where "/SiteAssets/common/thescripts.txt" is the URL of your HTML script.

27 Jul 2016

Using jQuery to Send Email from SharePoint

I’ve been outside of this blog so far and never post anything in this blog. But let me share a small code snippet that can be used. Below is the code to send email from SharePoint.


var EmailInfo = {
  To : { Address : 'radityo.ardi@gmx.com' },
  Subject : 'This is the subject',
  Body : 'This is the <b>Body</b>'
};

$.ajax({
 url: _spPageContextInfo.webServerRelativeUrl +
   '/_api/SP.Utilities.Utility.SendEmail',
 contentType: 'application/json',
 type: "POST",
 headers: {
  "Accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose",
  "X-RequestDigest": $("#__REQUESTDIGEST").val()
 },
 data: JSON.stringify({
  'properties': {
   '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
   'From': 'Radityo Ardi',
   'To': { 'results': [EmailInfo.To.Address] },
   'CC': [],
   'Subject': EmailInfo.Subject,
   'Body': EmailInfo.Body
  }
 }),
 success: function(dataSendEmail) {
  alert('Email successfully sent.');
 },
 error: function(err) {
  console.log(err);
 }
});

9 Okt 2015

Snippet: Strip HTML tags using jQuery

After quite a long time I never posted anything on my blog, now I’m ready to back. To begin the adventure again, I’ll post 1 interesting code snippet in jQuery.

Basically it is very hard for us to strip HTML tag in JavaScript, but we also know that jQuery is a powerful framework itself. I didn’t recognize this functionality after today I came into one thing in mind, how to strip HTML tag in JavaScript?

DSC_0017[1]

Now, let us see on the snippet below and enjoy…!

function stripHtml(htmlContent) {
    return $("<p>").html(htmlContent).text();
}