New Project Server CSOM API features released by MS

Microsoft posted an update to the CSOM API on Nuget last week, see the full announcement here: New SharePoint CSOM version released for SharePoint Online – January 2017

Significantly for those of us in the world of Project Server is the addition of a handful of new classes and methods for managing Enterprise Resource Cost Rates:

  • public class Microsoft.ProjectServer.Client.CostRateCreationInformation
  • public enum Microsoft.ProjectServer.Client.CostRateTableName
  • public property Microsoft.ProjectServer.Client.DraftAssignment.CostRateTable
  • public property Microsoft.ProjectServer.Client.EnterpriseResource.CostRateTables
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRate
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRateCollection
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRatePropertyNames
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRateTable
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRateTableCollection
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRateTableObjectPropertyNames
  • public class Microsoft.ProjectServer.Client.EnterpriseResourceCostRateTablePropertyNames
  • public class Microsoft.ProjectServer.Client.PageSizes
  • public class Microsoft.ProjectServer.Client.PageSizesPropertyNames
  • public property Microsoft.ProjectServer.Client.ProjectContext.PageSizes
  • public property Microsoft.ProjectServer.Client.PublishedAssignment.CostRateTable

(Copied from the Office Blog above)

Good news as that is one more step closer to CSOM / JSOM API parity with the now legacy PSI, also great news to see something new from MS for us poor neglected Project developers. ;)

Share and Enjoy !

Shares

New Project CSOM library sneak-peak

After reading all about the new SharePoint CSOM release but unfortunately not being able to read about the changes to the Project Online CSOM library included in the SharePoint release, I decided to take a sneak-peek myself to see what’s new.

Fortunately my favourite .Net Reflector tool (JetBrains dotPeek) came in handy here in addition to a diff tool (WinMerge) it is possible to identify the changes to the Microsoft.ProjectServer.Client.dll file immediately!

What’s new?

Well, below I have extracted from the differences the new properties and methods available, the list is probably not 100% complete as I focused most on the areas I use: Projects, Tasks, Assignments, Workflows and Timesheets, err so let’s say it’s pretty complete, however I may have missed some things.

In short the obvious new items relate to previously announced changes, such as the Project ID feature now available in Project Online; DraftProject.ProjectIdentifier, and the Create Project Site from workflow feature; PublishedProject.CreateProjectSite(string siteName).

However notably missing is the bulk update of custom fields method I would have expected (previously released for Project Online workflows), that’s slightly annoying if say you have an App that updates projects in bulk or something similar (*ahem*).

What else is interesting?

Some new Public Properties made available to developers:

  • (DateTime) DraftProject.UtilizationDate
  • (ProjectUtilizationType) DraftProject.UtilizationType
  • (ProjectSummaryTask) Project.ProjectSummaryTask
  • (StatusApprovalType) StatusAssignment.ApprovalStatus
  • (StatusAssignmentHistoryLineCollection) StatusAssignment.History
  • (Guid) StatusText.ProjectTaskId

As well as one new Public Method made available:

  • ProjectContext.GetDeletedPublishedAssignments(deletedDate)

Based on the names I think it’s safe to assume that most of those relate to the new 2016 Resource Engagements feature which is already available on Project Online, however apart from the new ProjectSummaryTask property unfortunately there doesn’t seem to be any breaking news here to report! :(

I guess we’ll just have to wait for the official announcement to hear any more..

(Mostly) Complete list of modified classes

Note: I’ve ignored a lot of minor changes that appear to be simple refactoring’s and focused only on the new Public Properties and Methods while ignoring a few Internal methods and such.

Assignment.cs

  • public WorkContourType WorkContourType

DraftProject.cs

  • public string ProjectIdentifier
  • public DateTime UtilizationDate
  • public ProjectUtilizationType UtilizationType

Project.cs

  • public ProjectSummaryTask ProjectSummaryTask

ProjectContext.cs

  • public DeletedPublishedAssignmentCollection GetDeletedPublishedAssignments(DateTime deletedDate)

ProjectServer.cs

  • public DeletedPublishedAssignmentCollection GetDeletedPublishedAssignments(DateTime deletedDate)

PublishedProject.cs

  • public string ProjectIdentifier
  • public DateTime UtilizationDate
  • public ProjectUtilizationType UtilizationType
  • public void CreateProjectSite(string siteName)

StatusAssignment.cs

  • public StatusApprovalType ApprovalStatus
  • public StatusAssignmentHistoryLineCollection History
  • public DateTime Modified

StatusText.cs

  • public Guid ProjectTaskId

(Mostly) Complete list of new classes and enumerations

  • public class DeletedPublishedAssignment : ClientObject
  • public class DeletedPublishedAssignmentCollection : ClientObjectCollection
  • public class ProjectSummaryTask : Task
  • public enum ProjectUtilizationType
  • public class StatusAssignmentHistoryLine : ClientObject
  • public class StatusAssignmentHistoryLineCollection : ClientObjectCollection
  • public enum StatusUpdateType
  • public enum WorkContourType

Hope that satisfied your curiosity…

Share and Enjoy !

Shares

Creating Project Tasks in a SPD Workflow

A lot has changed in Project Server workflows in the past few years, with the release of SharePoint 2013 and Office 365 the world of workflow completely changed. Fortunately SharePoint Designer’s (SPD) evolution into an actual usable tool for creating Project Server workflows filled the huge gap that previously existed for Project Server consultants and implementers, however at the same time the changes created a new major gap by completely blocking any sort of custom code in any workflows!

All is not lost though, with the changes in workflow we also received a handy set of new RESTful API’s to use so in theory at least we should be able to do a fair bit that previously required C# code via pure non-code-based SharePoint Designer workflows.

 

Putting the theory to the test

I have a theory with working with customers, that whatever is possible through the out-of-the-box features of a Microsoft product will never be enough after the first workshop. It seems that I like saying yes to customers. ;)

Scenario

My customer’s business process dictates that based on the result of an approval gateway the Microsoft Project schedule will require changes, specifically additional tasks need to be added to the schedule based on custom fields (or even a SharePoint list).

As there are no SharePoint Designer workflow actions that update project tasks, this would fall into the category of workflow built with Visual Studio (based on the MSDN: Decision tree: SharePoint Designer vs. Visual Studio), however the reality is that when you get down to it Visual Studio workflows share fundamentally the same limitation as those built in SPD i.e. declarative, no code workflows only (See the bottom of this article about some more practical limitations).

Solution

Let’s use my new favourite workflow action – the Call HTTP Web Service activity – in conjunction with the RESTful CSOM API for Project Server to actually create some tasks directly from SPD as follows;

  1. Get our task data – We’ll need task name, duration, start date, etc.
  2. Prepare our REST request – a bit of HTTP request header / body knowledge will be required but can be borrowed from some other examples like this one: Create a project site based on a custom field value.
  3. Post the http request and handle the result.

I’m going to skip a lot of details for this article and just focus on the above interesting bits, of course in the real world you’ll have to worry about publishing and checking out the project and although I don’t include those I will discuss check-out at least below as it is important. Additionally I will just create a single static task in this example, ideally you would get the values from custom fields, or better yet get a list of tasks to create using a separate OData http request then loop through creating each one.

 

PWA Workflow Configuration

Let’s keep this simple, you can use your imagination as to how this would fit into your requirement but I will even omit the approval and any other normal phases and stages.

Phases (Using Defaults):

1. Create

2. Manage

Stages:

1.1 Project Details – where we will get basic project details.

1.2 Create Tasks – where we will create the task(s) in the workflow.

2.1 Manage – we’re done, as you were..

wfstages

 

Begin the SharePoint Designer Workflow

Here’s one I prepared earlier:

basicSPD

 

Okay so I’m assuming that this is not your first ever workflow, so the above is the following: Stage transition including basic history / status messages, plus in [stage 1.2] we are manually (and statically!) creating a dictionary of properties for the task we are going to add. (This is static and as per my comment above you probably want to dynamically populate this dictionary even by just setting the value(s) to the value of specific custom fields.)

 

Note on Check-in / Check-out

The project will need to be checked out to update the schedule, fact. However SPD workflow runs in the context of the user who started it, i.e. the PM in most cases. So in this example I’m going to assume that the project is currently checked-out by the PM and just go ahead and do the update. You may be surprised but this will actually work, of course in reality you will have to check for this and if an error occurs then retry after checking-out – or conversely you could require the project be checked in before submitting and then do the check-out / check-in every time.

 

Preparing the new task dictionary

SPD uses extensively the Dictionary object in the HTTP Activity, both for the headers, body and return values, so to create our task we are going to need a dictionary formatted in the format expected by the Project Server REST API for creating new tasks. This is where it starts getting interesting.

It turns out that this is easier that you might have guessed, see those properties of the task; Name, Duration, ParentId, etc? Guess what dictionary values we’ll need? :)

dict1a

On the left is the complete dictionary, and on the right is the properties of the first “Name” row expanded. Surely it’s not that simple? For once yes it is.

So create the dictionary from the menu Action – Build Dictionary, populate the dictionary with the fields you want, specifically you’ll need Task Name as a minimum, and importantly pay attention to the data-type, for this the MSDN link above is handy, names are strings, dates are dates, parent task Id is a GUID, etc. (Note: Duration is text! Hello manual tasks!)

 

Prepare the HTTP request

Now we’ll need another dictionary for the request header, if you’ve previously read the MSDN article on using the Bulk update of custom field values, or my article on creating a Project Site based on a custom field, then you’ll see here we need the same thing.

dic2

Two string entries needed:

Accept: application/json; odata=verbose

Content-Type: application/json; odata=verbose

The great thing about SPD workflows is that it takes care of the authentication and any other headers, so that is everything that we need.

 

Submitting the HTTP request

Now we get to use my favourite activity: Call HTTP Web Servie.

Insert the activity, first click the this URL and we’ll build the request URL by basically calling the following REST resource endpoint: MSDN: PS.DraftTaskCollection.add Method, note from MSDN the syntax is as follows:

POST http://<sitecollection>/<site>/_api/ProjectServer/Projects('projectid')/Draft/Tasks/add(parameters)

So we need to dynamically create the URL as follows;

urlbuilder

  1. Use lookup params to insert the Workflow context: Current Site URL
  2. Append the text “_api/ProjectServer/Projects(”)/Draft/Tasks/add()
  3. Then insert the Project Data:Project UID into the text.
  4. Finally (importantly) Select HTTP POST as the HTTP method.

Next right click the activity and open properties to assign the request header and body, and while there specify something for at least the response content (so we can check the return http code).

httpReq

 

Check the Response

Okay we’ve made our REST call, now we just log the response to the status field, and to help with troubleshooting in the case where “responseCode” is not equal to “OK”, I actually log the full response to the history list.

(Warning! Logging to the history list like this has a max length of 255 characters, so if the error message exceeds that you will get another error and the workflow will fail! Use the Extract Substring activity to avoid this.)

You should now have something looking like this:

completeWK

Finally save and publish the workflow and you’re ready to go.

 

Time to test

Associate the workflow to an EPT, then create a project. As we’re not doing anything special in the first stage submit and you should see the workflow status info as “Building project schedule…” (looking good so far!).

Give it a minute and then refresh the page:

wftest2

 

Better yet, open the Schedule PDP and you will see our new task:

scheduleEg1

 

Neat.

Further Thoughts, Experiences and Limitations

This method opens up quite a few options when it comes to SharePoint Designer workflows, the ability to interact with all levels of the Project Server API via a workflow opens the possibility of working with any aspect of project data (tasks, assignments, resources, etc?).

However my experience of pushing this to the limit does raise some significant limitations:

  • SPD Workflows can contain a maximum of 50 local variables.

This sounds like a lot but it doesn’t take long before you’re needing to re-use variables, especially if you’re like me and you like nice verbose and unmistakable variable names. (Fifty max is killing me! ;))

  • Dictionaries are great but you can’t dynamically update them.

This is where we see the true limitations of SPD vs Visual Studio, doing a simple loop in code then adding the results to the end of a collection (array / dictionary etc) is pretty basic stuff, but with SPD can’t be done. You can loop yes sure, but you can only build a dictionary either statically (like I did above), or from the results of a query such as a http OData request.

  • Finally as a developer I’m going to call out this as a major limitation; single concern / no source control. (Ahhh!)

While creating some large workflows you don’t know how many times I have panic’ed thinking that an overly-long and unresponsive save or publish of my work has just crashed SPD and corrupted the whole workflow (it actually happened at least once), give me source control and a proper separation of concerns and let me sleep at night, please. :)

 

Recommended Reading

Here’s a great article on working with SPD dictionaries that I’d recommend: How to work with dictionaries in SharePoint 2013 and Office 365 workflow)

Complete basic operations using SharePoint 2013 REST endpoints

PS namespace MSDN reference (want to know what REST endpoints are available for Project Server?)

 

Download the solution

Create-Project-Tasks-Workflow.zip

 

Enjoy!

Share and Enjoy !

Shares

CICONotCheckedOut queue errors when updating projects via JSOM

I’ve written many times before about working with projects using the JSOM and CSOM API’s, and this is another issue in the API that I’ve had to resolve for one of my apps (in this case Bulk Edit).

Issue

When updating built in fields (I haven’t observed this for custom fields) using the client side library (JSOM or CSOM or REST) in the normal way the following error can be reported in the queue unexpectedly:

CICONotCheckedOut: CICONotCheckedOut (10102). Details: id=’10102′ name=’CICONotCheckedOut’ uid=’a2da51ea-792b-e411-9af1-00155d908811′.

Queue: GeneralQueueJobFailed (26000) – ProjectUpdate.FailIfNotCheckedOutMessage. …

For example the following code from the MSDN article on this topic will intermittently get the above error:

// Get the target project and then check it out. The checkOut function
// returns the draft version of the project.
var project = projects.getById(targetGuid);
var draftProject = project.checkOut();

// Set the new property value and then publish the project.
// Specify "true" to also check the project in.

draftProject.set_startDate("2013-12-31 09:00:00.000");
var publishJob = draftProject.publish(true);

// Register the job that you want to run on the server and specify the
// timeout duration and callback function.
projContext.waitForQueueAsync(publishJob, 10, QueueJobSent);

This is despite the fact that we are obviously doing the check-out of the project in line 4.

Worse still:

  1. The update will still work for most fields (like Status Date but NOT for Project Owner), despite the error indicating otherwise!
  2. The error is not consistent, some updates work without an error.

Cause and Solution

Turns out the issue is one due to the asynchronous nature of the client side libraries, specifically it looks like when performing the “waitForQueueAsync”  we are actually requesting four things:

  1. Check out Project
  2. Update project value (start date above)
  3. Publish Project
  4. Check project back in

However it seems that steps 2 and 4 don’t quite run in the correct order!  Changing line 10 as follows to NOT check-in after publishing results in a successful update and no error:

var publishJob = draftProject.publish(false);

Then we need to add a separate checkIn() call AFTER the completion of the publish (IE in the callback function ‘QueueJobSent‘ above) and then call waitForQueueAsync again.

Looks like a bug although perhaps not as it is important to keep in mind that the queued async jobs are not guaranteed to be done in the correct order although clearly it usually happens in the order expected.

 

BTW, Yes expect an update for Bulk Edit supporting more built-in fields soon!

Share and Enjoy !

Shares

Exploring REST Endpoints couldn’t be easier!

One of the best takeaways from ProjConf 2014 in my opinion was this gem by Chris Givens from Architecting Connected Systems:

http://sprest.architectingconnectedsystems.com/ 

Basically if you are working with the CSOM, JSOM or REST client side APIs for Project Server and SharePoint (and if you were at ProjConf after all the great sessions you have no excuse NOT to be! ;]), then you’ve probably found yourself browsing the REST endpoints to find what you need. I do all the time, in fact I will be writing about doing so for my Holiday Sync write up to be posted soon.

Using SPREST though this is made super easy, you can browse UP or DOWN the hierarchy of objects to find what you need (e.g. BaseCalendarExceptions) and it generate the code you need to use it via REST, CSOM or JSOM!

Not only that it has a voting feature where you can submit to MS (via Chris) suggestions of what unexposed methods you want to see in the client side that are exposed in the server side! Sweet.

 

It’s currently in Alpha, so check the site and support it by clicking on ad’s or buying the app when it’s out!

Share and Enjoy !

Shares