Creating random value via REST API

lastDigYear = Math.floor((Math.random() * 6) + 1);
lastDigMonth = Math.floor((Math.random() * 8) + 1);
AllDigDay = Math.floor((Math.random() * 15) + 1);

TolastDigYear = lastDigYear + 1;
TolastDigMonth = lastDigMonth + 1;
ToAllDigDay = AllDigDay + 3;


var data2 = {
            __metadata: { ‘type’: ‘SP.Data.Form70ListItem’ },
           Title: ‘Please provide title here’,
           ReportingPeriodFrom: ‘201’+lastDigYear.toString()+’-0’+lastDigMonth.toString()+’-‘+AllDigDay.toString()+’T15:18:21.135Z’,
           ReportingPeriodTo: ‘201’+TolastDigYear.toString()+’-0’+TolastDigMonth.toString()+’-‘+ToAllDigDay.toString()+’T15:18:21.135Z’,
           PartSources: Math.floor((Math.random() * 100) + 1),
           ActivePermits: Math.floor((Math.random() * 100) + 1),
           InitialPermitsPeriod: Math.floor((Math.random() * 100) + 1),
           InitialPermits18Months: Math.floor((Math.random() * 100) + 1),
           RegionId: Math.floor((Math.random() * 10) + 1),
           PermitAuthId: Math.floor(Math.random()*(158-42+1)+42),        
           OutstandingInitialApps: Math.floor((Math.random() * 100) + 1),
           OutstandingRenewalPermits: Math.floor((Math.random() * 100) + 1),
           SignificantModPeriod: Math.floor((Math.random() * 100) + 1),
           SignificantMods18Months: Math.floor((Math.random() * 100) + 1),
           OutstandingSignficantMods: Math.floor((Math.random() * 100) + 1),
           Form70comments: ‘Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden’,
      };

$.ajax({
    url: “/_api/web/lists/GetByTitle(‘Form70’)/items”,
    type: “POST”,
    data: JSON.stringify(data2),
    headers: {
        “X-RequestDigest”: $(“#__REQUESTDIGEST”).val(),
        “accept”: “application/json; odata=verbose”,
        “content-type”: “application/json;odata=verbose”
    }
}).done(function () {
    console.log(“Done”);
}).fail(function () {
    console.log(“FaiL”);
});

Getting Started: Authentication using JavaScript

This example does not use AngularJS or/and ADAL. There is no UI. The functions need to be run from the console and the access token extracted from the URL. A Azure active directory application was create to provide the client id. It works like:

Construct a URL that take the user to a log-in screen
Once the user log in an access token is returned in the URL
That access token is extracted and used in the REST request to get the SharePoint Online resources
(Interestingly you are calling cross domain and not using SP.RequestExecutor)

VSO project JavaScript Auth


Create and add data to a file in SharePoint Online using JavaScript

$(document).ready(function () {

    clientContext = SP.ClientContext.get_current();

    $(“#btnPublish”).click(function () {
        getSPItems();
    });

    function getSPItems() {

        var spList = clientContext.get_web().get_lists().getByTitle(‘Team_Members’);

        var camlQuery = new SP.CamlQuery();

        listItems = spList.getItems(camlQuery);

        clientContext.load(listItems);

        clientContext.executeQueryAsync(saveHtmlFile, onFailure);
    }

    function saveHtmlFile() {

        // var fileContent = uiContext.getJSContent();
        var fileContent = “”;
        Enum = listItems.getEnumerator();
        while (Enum.moveNext()) {
            GetTitle = Enum.current.get_fieldValues();
            fileContent += ” <div style=’position:relative;padding-bottom:10px’><img src='” + GetTitle.Image.$1_1 + “‘ alt=’employee Images’ style=’position:absolute’ height=’87’ width=’87’> <ul style=’padding-left:125px;list-style-image:url(../Images/tinyArrow.gif)’><li style=’padding-bottom:5px’><span style=’font-weight:bold’>” + GetTitle.Title + “</span></li><li style=’padding-bottom:5px’><span style=’font-weight:bold’>” + GetTitle.Position + “</span></li><li style=’padding-bottom:5px’><span style=’font-weight:bold’>” + GetTitle.Department1 + “</span></li><li class=’lastInRow’ style=’padding-bottom:5px’>” + GetTitle.Bio + “</li></ul></div>”;

        }

        var jsContent = “(function () {“
                          + “$(‘#divContent’).html(“” + fileContent + “”);”
                          + “})();”;

        var filesLibrary = clientContext.get_web().get_lists().getByTitle(“JSCompile”);
        var fileCreateInfo = new SP.FileCreationInformation();

        fileCreateInfo.set_url(“publish.js”);
        fileCreateInfo.set_overwrite(true);
        fileCreateInfo.set_content(new SP.Base64EncodedByteArray());

        for (var i = 0, fileLength = jsContent.length ; i < fileLength; ++i) {
            fileCreateInfo.get_content().append(jsContent.charCodeAt(i));
        }

        // Upload the file to the root folder of the document library
        this.newFile = filesLibrary.get_rootFolder().get_files().add(fileCreateInfo);
        clientContext.load(this.newFile);
        clientContext.executeQueryAsync(updateContentVersionNumber, onFailure);
    }

    function onFailure(sender, args) {
        alert(“Publish Failed: ” + args.get_message() + “nIf this error continues please contact: thesharepointhelper@gmail.com”);
    }

    function updateContentVersionNumber() {
        alert(“Publish Successful”);
    }

});

Getting Started: SharePoint Online approval workflow

Audio transcript:

In this video series, we’ll be discussing SharePoint approval workflows. Now there are several types of approval workflows that can created in various ways and with varying complexity, but in these next few tutorials we’ll focus on a simple serial workflow with a single approver. We’ll do this by going from basic to advanced. Our basic serial workflow will be created based on SharePoint online OOTB template, and then we’ll move on to complete the same workflow in SPD 2013 and then move on to VS 2012. Here you can see the most basic serial approval workflow. In future videos, we’ll discuss parallel workflows such as this, but for now, we’ll be focused on serial workflows. 

First we’ll look at the OOTB workflow template in SharePoint Online. I’ll create a new document library and add the approval workflow to it and set the workflow to automatically start when an item is created. Next I’ll add an approver to my workflow, in this case im using a test user called SPO test 5. I’ll ignore these other options for now and click save. Now I’ll upload an item, in this case it will be an image, but this will work for excel file, word documents, and pdfs ext …

After I’ve uploaded my item and refreshed the page, you can see that the workflow is in progress. Now we’ll open Office 365 outlook as our test user (SPO test 5) and see the email notification details. You can also open the document library item via this notification.

One of the disadvantages to this type of workflow can be found here in the body of the email. If you’ll notice step 3 says Use the “open this task” button to mark this task as complete. If I received this email in an outlook client application and not in Office 365, a button might be used to complete the task. However, for the approver to complete the task, they will need to navigate to the task list and approve the item. Once the task has been approved the workflow is complete. Now we’ll discuss how to accomplish this same workflow in SPD 2013.

If you found this video helpful and want to see more videos like this please subscribe and/or give us the thumbs up. 

 

SharePoint apps: Sending an email notification in a Visual Studio workflow

Auto Transcript:

Now we will discuss sending email notifications in SharePoint Online via Visual Studio workflows. There can be many ways to do this, but for simplicity, in this video we will simply get the email address from a text column in a list as show here in this introduction clip. Now to get started we will create a SharePoint-hosted application in visual studio 2012 pro. Once our project has been created, we’ll add a list and we’ll add a list workflow that starts automatically when an item is created. Now I won’t narrate all of the next steps of adding workflow activity or assigning variables, because in future videos we’ll go into more details about toolbox activities like “LookupSPListitem”. However, I will draw your attention to the BuildCollection activity because it’s the key part of how emails are sent in this scenario. Now, when I have finished building the workflow, I will launch it on my Office 365 developer site and test it by opening the list and creating a new item. 

Upcoming topics include: 

– Email notification workflows based on document author
– A closer look at “LookupSPListItem” activity  

Javascript Object Model: Get all site users

<script type=”text/javascript”>
    ExecuteOrDelayUntilScriptLoaded(getWebUserData, “sp.js”);  
      function getWebUserData() {
       var clientContext = new SP.ClientContext();
   var groupCollection = clientContext.get_web().get_siteUsers();
     clientContext.load(groupCollection);
          
      clientContext.executeQueryAsync(function () {
        Enum = groupCollection.getEnumerator();
        while (Enum.moveNext()) { 
        Enum1 = Enum.get_current(); 
        console.log(“Login Name ” + Enum1.get_loginName());
        console.log(“Email  ” + Enum1.get_email());
        console.log(“Title  ” + Enum1.get_title());
        console.log(“User Id  ” + Enum1.get_userId());
        }   
    }, function (err) {
        alert(‘fail’);
    });
      }
        </script>

How do I add and audio player to my SharePoint Online player?

Video Transcript:

Next we will demonstrate how to add an video to you SharePoint Online site. Our first step will be to add an asset library. Now we will add our video/audio file to this library. Once the file has been added we will return to the page where we want to show the video. When we edit the page, a drop-down in the ribbon will allow you to select the file you just uploaded to the asset library. Now save the page and your video will be available to view by your users. 

If you found this video helpful and want to see more videos like this please subscribe and/or give us the thumbs up.

How do I add a video to my SharePoint Online site?

Video transcript:

Next we will demonstrate how to add a video to your SharePoint Online site. Our first step will be to add an asset library. Now we will add our video/audio file to this library. Once the file has been added we will return to the page where we want to show the video. When we edit the page, a drop-down in the ribbon will allow you to select the file you just uploaded to the asset library. Now save the page and your video will be available to view by your users. 

If you found this video helpful and want to see more videos like this please subscribe and/or give us the thumbs up. 

Anonymous user access and the SharePoint 2013 JavaScript Object model

Looks like anonymous user can access pages in both “Pages” and “SitePages”. However, anonymous only have access to a sub-set of the SP namespace. For, instance SP.ClientContext is not available to the anonymous user, which means I can’t access a list even to read it’s data.

It looks like when a app is installed on the public site, the SP.ClientContext is available, but you get and error:

Uncaught Error: Sys.InvalidOperationException: Cannot find current web URL information on the page.

I get the above error even if i’m logged it and the cause is the plain .html page. If I use and .aspx I don’t get the error.

I even tried using REST to access the data in the list. This doesn’t make sense even though the list says the items in the list can be viewed, you can’t view the items with REST or via the JavaScript object model.

————————————————————————————————————-

I have created a SharePoint-hosted app, added in to my app catalog and installed it on my SharePoint Online public facing site. The app has a list titled “EmployeeRec” and when I go to this list I clearly see that the anonymous users have “View Items” access. However, when I try to read items from the list as an anonymous user I get access denied errors. I have tried reading items from the list using both the JavaScript Object Model and REST, and I get access denied using both techniques.

LIst of a SharePoint-Hosted app installed on public facing site anonymous user
List of a SharePoint-Hosted app installed on public facing site anonymous user