Archive

Posts Tagged ‘CSOM’

#PS2013 #MSProject Online CSOM documentation links #ProjectServer #Office365

So as I continue my investigations into the CSOM for Project Server 2013 and Project Online (Office 365), I came across the following articles on MSDN.

Hopefully others will find these articles useful also:

High level project CSOM details

What’s new for developers in Project 2013 – CSOM

Client-side object model (CSOM) for Project Server 2013

Project Server CSOM – Sample Code – JavaScript and .NET

Getting started with the Project Server 2013 JavaScript object model

Getting started with the Project Server CSOM and .NET

How to: Create, retrieve, update, and delete projects by using the Project Server 2013 JavaScript object model

Project Professional 2013 CSOM – Sample Code – JavaScript

Project 2013 client programming

Task pane apps for Project Professional 2013

Task pane apps for Project

How to: Create your first task pane app for Project 2013 by using a text editor

JavaScript API for Office

Understanding the JavaScript API for Office

Schema map (apps for Office)

Advertisement

Retrieving the Project GUID with JavaScript CSOM #PS2013 #PS2010 #MSProject #Office365 #in

July 20, 2012 5 comments

So the Microsoft Office preview is out and unfortunately my colleagues and I are still consulting on current and previous versions, so only limited time around client work allows for play.  Luckily we have had access to earlier versions for several months now so as a company Corporate Project Solutions is prepared for 2013 and we are even running knowledge sessions and upgrade validation checks.

Moving on… whilst in the hotel, we started playing with Napa and the possibilities around what can and can’t be done.

Although this example is not relevant to Napa (due to the environment the apps run in), we did manage to product some code that would be useful for Sandbox Solutions or Composite solutions using the Content Editor Web Part in Project Online, Project Server 2013 and potentially Project Server 2010.

In this example, we use the SharePoint Client Side Object Model to view the property bag within a Project Site to retrieve the following:

  • Internal Project UID
  • Project Wep App URL
  • Project Web App Site UID.

NB: The Project UID is for the plan associated within to the site in Project Server.

The Result

image

SharePoint CSOM code running within a Project Site in Project Online (Office 365 Preview)

 

image

Closer look at the output

 

So you may be wondering, why we need this information.  Well with the introduction of Project Online / Project Server 2013, the client side object model can interact with the PSI to return Project and Resource data.

In many cases you will need the Project UID as a starting point!

Here are the details of getting things up and running in the IE Development Toolbar Smile and trust me, there is much more CSOM goodness to come.

 

Final Code Example:

function getWebProperty() {
    var ctx = new SP.ClientContext.get_current();
    this.web = ctx.get_web();
    this.props =  this.web.get_allProperties();

    ctx.executeQueryAsync(
       Function.createDelegate(this, gotProperty), 
       Function.createDelegate(this, failedGettingProperty)
    );
}

function gotProperty() {
    alert("Project UID: " + this.props.get_fieldValues()["MSPWAPROJUID"]
     + "\nPWA URL: " + this.props.get_fieldValues()["PWAURL"]
     + "\nPWA Site UID: " + this.props.get_fieldValues()["MSPWASITEUID"]
    ); 
}

function failedGettingProperty() {
    alert("failed");
}

getWebProperty();

Debug Code Example:

To get this detail out, me and my colleague had to do some digging in the object model using debug code to alert out to the console values at the Web and Property object areas:

function getWebProperty() {
    var ctx = new SP.ClientContext.get_current();
            for(var p in ctx)
            {
                        console.log("T: " + p);
            }
    this.web = ctx.get_web();
    this.props =  this.web.get_allProperties();
    ctx.load(this.web);
    ctx.load(this.props);

    ctx.executeQueryAsync(
       Function.createDelegate(this, gotProperty), 
       Function.createDelegate(this, failedGettingProperty)
    );
}

function gotProperty() {
            //alert(props.isPropertyAvailable('allowdesigner'));
            for(var itm in this.web){
                        console.log(itm);
            }
            for(var prop in props){
            console.log(prop);
            }
            for(var fv in this.props.get_fieldValues())
            { 
                        console.log(fv);
            }
            alert(this.props.get_fieldValues()["MSPWAPROJUID"]); 
}

function failedGettingProperty() {
    alert("failed");
}

getWebProperty();

 

Example References

Just in case you need to add sources for JavaScript frameworks.  Here are some references below:

<script type="text/ecmascript" src="/_layouts/SP.Core.js" />

<script type="text/ecmascript" src="/_layouts/SP.Debug.js" />

<script type="text/ecmascript" src="/_layouts/SP.Runtime.Debug.js" />

<script type="text/javascript" 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" />

 

%d bloggers like this: