Tag Archives: SharePoint 2013

Show modal dialog form from another site collection

Ever get an error message saying “Refused to display ‘url’ in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN‘.” when trying to load a list form from another site collection in a modal dialog? ¬†Add this to a line right after the last <% Register tag on the masterpage:

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Populate a SharePoint 2013 PeoplePicker field using JavaScript/jQuery

Here is a quick and fairly simple way to programmatically populate a SharePoint 2013 People Picker field with a user based on their email address. This example assumes you have more than one People Picker field on the page. You will need:

  • The display name of the People Picker Field
  • The email address of the user you want to add to the People Picker Field

Add the following code to either a Script Editor Web Part (inside <script> tags) or on your page in the PlaceHolderAdditionalPageHead, also in <script> tags:

var dispTitle = "";
var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];
var usrObj = { 'Key': 'email@address.com'};
peoplePicker.AddUnresolvedUser(usrObj,true); 

In one case, I had to remove the “title” attribute filter from the pickerDiv var to get it to work, but it was the only People Picker on the page, so we were good.

Hope this helps!

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Know REST For the Query – SharePoint Saturday Phoenix 2014

Thank you for all who attended my session, below is the video. Big thanks to Becky Bohanon for enhancing the audio!

The slide deck is available here: Slide Deck

The JavaScript file that was used to do all of the REST calls is available here: demo.js

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Complete Guide to Making and Parsing REST calls using SharePoint Designer 2013

Recently I needed a sequential workflow that makes a REST call to another website (non-SharePoint), retrieves some JSON data, parses it, and makes decisions based on that data. Oh, and I’m not allowed to use Visual Studio in this case, it has to be SharePoint Designer (ugh). Continue reading Complete Guide to Making and Parsing REST calls using SharePoint Designer 2013

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Read a SharePoint list using JavaScript

There are countless ways to read data from a SharePoint list, and also myriad methods to do this in JavaScript, but I’m going to document this one way as a place to get started, and a published function I can refer back to if needed!

First consider the following: Reading SharePoint list data using JavaScript requires the SP.js file to be loaded already. So, we should be putting this function inside of a $(document).ready(function())}; and if needed inside an ExecuteOrDelayUntilScriptLoaded(functionName, ‘sp.js’); Once in there, it would look something like this:

function readFromList() {
    var query = new SP.CamlQuery();
    query.set_viewXml('');
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('List Name');
    var items = oList.getItems(query);
    clientContext.load(items);
    clientContext.executeQueryAsync(function () {
        if (items.get_count() > 0) {
            var enumerator = items.getEnumerator();
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                var field = listItem.get_item('Field Name');
            }
        }
    }, function(sender, args) {
        console.log(args.get_message());
    });

I’ll go over each line to explain what’s happening:
var query = new SP.CamlQuery(); – this is preparing a CamlQuery object using SP.js (which is why it’s important to wait for it to be loaded!)
query.set_viewXml – Here’s where you define your CAML query using normal CAML syntax. In the above scenario, it will return the Title field from all items in the list.
var clientContext = SP.ClientContext.get_current(); – this establishes a client context object using the current Site Collection.
var oList = clientContext.get_web().get_lists().getByTitle(‘List Name’); – this creates an object that references the specific list in the specific web you wanted to pull items from.
var items = oList.getItems(query); – this is saying get the items from the list object based on the query defined above.
clientContext.load(items); – you’re now telling the object model to prepare to execute the following object by loading it into the client context.
clientContext.executeQueryAsync – ok, here you actually execute the query you so dutifully prepared just a moment ago. This operation expects a “Success” function and a “Failed” function to be passed in or referred to somehow. The success function will be what you want to do once the query is done executing. The failed function will be how you want to handle any issues.

In the above example, the success function looks like this:

if (items.get_count() > 0) {
            var enumerator = items.getEnumerator();
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                var field = listItem.get_item('Field Name');
            }
        }

What this is doing is looping through the results of the query and reading each one. The key is, to read a field value the syntax is listItem.get_item(‘Field Name’). Again, lots of ways to read field data, especially system fields like ID, this is just one example.

To handle errors I simply have whatever the error message is log to the console. At this point you can do what you like with the resulting data: put it in a string array and read it later, push it out to the page, make decisions based on the results, etc. Hope this helps!

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube