Running #ProjectOnline #PowerShell in #Azure using #AzureFunctions #PPM #Cloud #Flow #LogicApp Part2

August 1, 2017 at 4:32 pm | Posted in Add-on, Administration, Configuration, Customisation, Functionality, Information, PowerShell, Workflow | Leave a comment
Tags: , , , , , , ,

Following on from part 1 where I introduced the idea of automating certain Microsoft 365 PPM Project Online customisations using PowerShell, Microsoft Flow / Azure Logic Apps and Azure Functions, in part 2 I will set up an example automation for creating a Project Online event driven snapshot application on project published without having to set up any server or write any complied code! If you missed part 1 where this concept was introduced, see the link below:

https://pwmather.wordpress.com/2017/07/28/running-projectonline-powershell-in-azure-using-azurefunctions-ppm-cloud-flow-logicapp-part1/

Firstly I created an Azure Function app in my Azure subscription then created a new function based on the HttpTrigger – PowerShell template:

image

Give the function a name and set the Authorisation level – set the authorisation level to the correct setting for your function. Click Create. For details on Azure Functions, start here: https://docs.microsoft.com/en-us/azure/azure-functions/

You will then be presented with the function and sample code:

image

We will now create the PowerShell script to create the snapshot. This is based on a script I published a while back: https://pwmather.wordpress.com/2016/08/26/projectonline-data-capture-snapshot-capability-with-powershell-sharepoint-office365-ppm-bi/

The script has been updated to work in an Azure Function but also modified to use a parameter so that it only captures data for the published project, the PowerShell script can be seen further on in the post.

Firstly upload the SharePoint CSOM DLLs using the upload button:

image

I used the SharePoint CSOM DLLs from the SharePoint Online Management Shell:

image

Then enter the PowerShell code – screen shots below and code pasted below the images:

image

image

image

Code sample used in function:

# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$projID = $requestBody.projID

# GET method: each querystring parameter is its own variable
if ($req_query_name) 
{
    $projID = $req_query_name 
}

#add SharePoint Online DLL - update the location if required
Import-Module "D:\home\site\wwwroot\ProjectSiteUserSyncHTTPTrigger\Microsoft.SharePoint.Client.dll"
Import-Module "D:\home\site\wwwroot\ProjectSiteUserSyncHTTPTrigger\Microsoft.SharePoint.Client.Runtime.dll"

#set the environment details
$PWAInstanceURL = "https://mod497254.sharepoint.com/sites/PWA2"
$username = "admin@MOD497254.onmicrosoft.com" 
$password = "password"
$securePass = ConvertTo-SecureString $password -AsPlainText -Force
#create the SharePoint list on the PWA site and add the correct columns based on the data required
$listname = "ProjectSnapShots"
$results1 = @()

#set the Odata URL with the correct project fields needed
$url = $PWAInstanceURL + "/_api/ProjectData/Projects()?`$Filter=ProjectId eq GUID'$projID'&`$Select=ProjectId,ProjectName,ProjectPercentCompleted"

#get all of the data from the OData URL
while ($url){
    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass);    
    $webrequest = [System.Net.WebRequest]::Create($url)
    $webrequest.Credentials = $spocreds
    $webrequest.Accept = "application/json;odata=verbose"
    $webrequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
    $response = $webrequest.GetResponse()
    $reader = New-Object System.IO.StreamReader $response.GetResponseStream()
    $data = $reader.ReadToEnd()
    $results = ConvertFrom-Json -InputObject $data
    $results1 += $results.d.results
        if ($results.d.__next){
        $url=$results.d.__next.ToString()
    }
    else {
        $url=$null
    }
}

#add data to snapshot list
#get PWA site client context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($PWAInstanceURL) 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass) 
$ctx.Credentials = $credentials 
$ctx.ExecuteQuery()  
 
#get the target list 
$List = $ctx.Web.Lists.GetByTitle($listname) 
$ctx.Load($List) 
$ctx.ExecuteQuery() 

#for each project, create the list item - update the newitem with the correct list columns and project data
foreach ($projectrow in $results1) 
{ 
   $itemcreationInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation 
   $newitem = $List.AddItem($itemcreationInfo) 
   $newitem["Title"] = $projectrow.ProjectName
   $newitem["ProjectId"] = $projectrow.ProjectId
   $newitem["PercentCompleted"] = $projectrow.ProjectPercentCompleted
   $newitem.Update() 
   $ctx.ExecuteQuery() 
} 

The PowerShell code would need to be updated with your environment details: (PWAInstanceUrl, username, password and listname variables). Also the OData URL will need to be updated to include the project level fields that you want to snapshot.The target SharePoint list will also need to be set up in the PWA site collection for the project fields the script uses. This is the list I set up for this example:

image

SnapshotDate is set to Todays date so we don’t need to set that in the code.

The code is simple to follow but in summary the first part will get the projID from request body – we will pass in the ProjectID for the published project from the Flow / Logic App trigger. Then the SharePoint Online CSOM DLLs are imported in. Then the specific PWA environment details are set for the variables. The OData URL is then added to the url variable. Here notice we are filtering for the ProjectID and passing in the $projID variable we get from the request body. The Select part of the query will need to be updated for your project level fields. Next the code gets the data from the OData feed using the web request and adds the data into the results array. Once we have the data, we connect to the SharePoint list, in the example it is the ProjectSnapShots as set in the $listname variable. Lastly the new item is created in the list using the data from the results array.

Now the Azure Function is ready to be used. It can be tested using the Test option in the right hand panel, update the Request body:

image

Update it for a valid project ID. Then click Run above the function code:

image

The Logs window below will help you debug any errors etc.:

image

Then check the SharePoint list in the PWA site and the new item should have been created:

image

We now know the Azure Function is working as expected, now we need to call the Azure function when a project is published. All we need from the Azure Function is the URL to use, use the </>Get function URL button:

image

Select the correct Key, in this example I used the default function key. Copy the URL as it will be needed later.

To call the Azure Function when a project is published, the choice here for a no code option would be Microsoft Flow or Azure Logic App. For this I will use Microsoft Flow but the same steps (triggers , actions etc.) would be used in the Azure Logic App. Create a new Flow and search for Project Online:

image

Then select the Project Online – When a project is published trigger.

Enter the PWA URL:

image

Then click the ellipsis and set the connection for the PWA URL or create a new connection if needed:

image

Click + New step then Add an Action and search Http:

image

Select HTTP – HTTP:

image

Complete the HTTP action:

Method is POST, the Uri is the URL for the function that we copied earlier, Headers are not required. The Body is where we pass in the project ID from the published project trigger:

image

The Flow is now completed:

SNAGHTML55ecdca7

Now click Save flow.

In PWA, Publish a project or projects and see the snapshot data created on the configured snapshot list once the Flow has run:

Flow run:

image

Data added to the list for the project I published – in this example it was the Office 2016 rollout project:

image

This just shows a simple example and the some of the possibilities for extending the Project Online capability when making use of simple PowerShell scripts and other Microsoft 365 / Azure services for cloud / serverless solutions. Look out for more examples in the future.

Advertisements

Running #ProjectOnline #PowerShell in #Azure using #AzureFunctions #PPM #Cloud #Flow #LogicApp Part1

July 28, 2017 at 4:50 pm | Posted in Add-on, Administration, App, Configuration, Customisation, Fixes, Functionality, Information, PowerShell, Workflow | 4 Comments
Tags: , , , , , ,

Following on from my last post where I published an example solution starter PowerShell script for adding project team users to the Project Site, here I mentioned about running the script in an Azure Function and even running this sync from a Project Online event. The blog post can be seen below if you missed that:

https://pwmather.wordpress.com/2017/07/07/projectonline-project-user-sync-to-project-sites-ppm-o365-powershell-sharepoint/

Whilst I will use that example PowerShell script from my last blog post as an example, the concept will work for any PowerShell script.

I wont cover the details in setting up the Azure Function in part 1 as there is plenty of support out there for this – for this example I created an Http Trigger – PowerShell function.

image

I then uploaded the SharePoint DLLs and copied in the PowerShell script into the editor:

image

The project site user sync script didn’t work as is as I had to make some minor changes to get this to run from the Azure Function. This included change the way the SharePoint CSOM DLLs where loaded in. In the example script I used Add-Type to load the DLLs but in the Azure Function I had to switch this out to use Import-Module:

image

The next change I had to make was to comment out all of the feedback to the console, so all of the write-hosts. I also had to remove the functions within the script so that is was one block. After these changes I could execute the PowerShell script to add the project team members from my example project into the associated project site from the Azure Function. As this was an HTTP Trigger Azure Function, you can get the URL to the function and access that URL to execute the function.

This opens up lots of possibilities to easily execute this Azure Function from other applications that can make the HTTP call. For example you build easily execute this script once the project has been published either using a remote event receiver (RER) or a Microsoft Flow / Azure Logic App. The example script would need to be made generic and pass in a variable into the Azure Function for it to be a workable solution.

In part 2 of this blog post we will look at make a full event driven solution that is fired on project publish then executing the Azure Function and passing in a variable.

Introduction to #Microsoft Flow with #ProjectOnline #IFTTT #WebHooks #OfficeDev #Yammer #Office365

May 6, 2016 at 12:11 pm | Posted in Add-on, Administration, Configuration, Customisation, Functionality, Information, Workflow | Leave a comment
Tags: , , ,

At the end of April Microsoft’s Flow was made available as preview. Microsoft Flow is an If This Then That (IFTTT) service with many built in web hooks or connections to different services. You can connect to services like SharePoint Online, CRM or Twitter to name a few. A blog post from Microsoft can be found here.

In this post we will see an example of using Microsoft’s Flow service with Project Online – Microsoft’s Office 365 PPM application. When a project is created we will post a message in Yammer. Once signed in, click on My Flows from the top navigation bar:

image

From here you can view preconfigured templates or create from blank. Currently there aren’t any templates for Project Online so click create from blank. On this page you will see all of the services you can work with currently in the preview version:

image

Either start typing Project or scroll down the list to Project:

image

For this example I will choose “Project Online – When a new project is created”. You then need to sign into the Project Online PWA site:

image

Enter your credentials for the target Office 365 tenant when requested. Then enter the URL of the PWA site:

image

Now click the + button to either add an action or add a condition:

image

For this example we will just add an action without any conditions. You can add conditions in if needed though like below, if the project name contains “delivery” do something:

image

Also notice the advance mode where you can type the query condition:

image

For this demo we don’t need any conditions so I will remove that and just add an action and search Yammer:

image

Then select “Yammer – Post message” and click the sign in link then follow the steps to allow the access:

image

It’s your call to allow the access or not for services for this demo I have but only do this if you accept the terms of service. Then you can complete the details for the Yammer post:

image

This is what I have done:

image

Then give the Flow a name:

image

Click Create Flow and after a few seconds you will see the message stating this was created:

image

Click Done and the wizard is complete:

image

You can edit / delete the Flow from the My Flows page:

image

Now if I create a Project in that Project Online instance a new post will be created in the Yammer group. There maybe a minute or so delay before you see the post in the Yammer group once you create the project but here it is:

The project – “Paul Mathers test project”:

image

In Yammer, the post including the project name:

image

Notice the post if from Microsoft PowerApps.

You can check the Flow runs from the My Flow pages, click the i button at the end:

image

You will then see the following:

image

This is just a simple example – there is so much you can do even in the preview version of Flow – I’m sure more and more web hooks and functionality will be added before this is GA. Take a look today, it is very easy to use as you can see.

Getting started with #ProjectOnline #Workflow Part 1 #PS2013 #Office365 #Project #PPM #PMOT

February 9, 2016 at 1:09 am | Posted in Add-on, Administration, Configuration, Customisation, Functionality, Information, Workflow | 2 Comments
Tags: , , , ,

Following on from a very popular series of posts on getting started with Project Online, Microsoft’s Office 365 PPM cloud offering, round up found here. I started a mini series towards the end of last year where I covered getting started with the Portfolio Analysis functionality, part 1 here and part 2 here. I mentioned here that I would also do the same for workflow. I have finally got around to creating the workflow version – sorry for the delay, it has been a busy few months.

In this series of posts I will touch on some of the workflow capabilities that are available for Project Online and show you how to getting started.

For the purpose of this post I have already configured a project ideas type list in my PWA site collection, the portfolio strategy / analysis piece, some enterprise project types and have some custom fields.

The first post in this series will look at creating a project from the project ideas list. The workflow will assign a task to a SharePoint group for the approval, once approved a project will be created in Project Online using the correct Enterprise Project Type.

The project ideas list on my test environment looks like this:

image

image

Very simple, with a couple of SharePoint fields. I have mapped these fields to Project Online custom fields:

image

This is so that the metadata captured from the idea is copied over to custom field when the project is created.

I have also created some new Enterprise Project Types in this test environment:

image

Some of these will be used in later posts for this getting started series.

We will now look at creating an approval workflow for this ProjectIdeas list. Launch SharePoint Designer 2013 and open the target PWA site.

image

Click Workflow from Navigation pane:

image

Click List Workflow then choose the list:

image

Complete the details as required:

image

Click OK.

image

Now you can start creating the workflow in the designer. For this example I will firstly insert two more stages using the Stage button:

image

Then rename the stages:

image

Starting with the Initiated stage, click where is states “Start typing…” and more options will be enabled in the ribbon:

image

Click the Action button and scroll down to the “Assign a task” action and click:

image

Now click this user:

image

In the dialog box that appears complete the details, for the Participant I selected the Administrators group:

image

For the task title I used the string builder and added the following with a lookup to the item:

image

For the description I used the string builder to create the following:

image

Once the details are completed:

image

Click OK.

Now click in the transition to stage section:

image

Using the condition ribbon menu button, select if any value equals value:

image

Now click the first value:

image

Then click the fx button:

image

In the box that appears set the following:

image

Click OK.

Click the second value and choose Approved:

image

Now select the Insert go-to under the If and select Go to a stage on the Action menu:

image

image

Click a stage and select Approved:

image

Do the same for Else but select the Rejected stage:

image

In the Approved stage I will insert a parallel block:

image

In this parallel block I will insert four If conditions:

image

The If conditions are then configured like below:

image

The action for each If will be “Create Project from Current Item”:

image

Then you can choose the Enterprise Project Type:

image

Set this up to match to correct EPTs:

image

I then added two further actions:

image

To send ad email and to set a field on the list.

The email was configured as below:

image

The workflow then set the Approval Date field to Today:

image

The transition to stage was then update to end the workflow:

image

The final stage to configure is the Reject stage, in this stage we just send and email to the user that created the item then end the workflow:

image

Once completed, save the workflow and check for any errors.

Using the navigation bar, click the workflow name:

image

Then set the start options for the workflow:

image

Once you are happy with it publish the workflow to the list.

Back in SharePoint, if we look at the Workflow settings for the list we should see the workflow name:

image

Now if I create a new item on the list the workflow will fire and create a task for one of the administrators to approve, the item shows as in the initiated stage:

image

As a PWA administrator I would receive a email notifying me that I had a task assigned, I could then approve that item or reject it. In this example I will approve it:

image

When the workflow fires the item will update to Approved, a project will get created in Project Online, an email will be sent to the user who created the idea and the Approval Date will be set on the list item.

The updated project idea item can be seen below:

image

The project can be seen below in the project center with the correct Enterprise Project Type:

image

The data from the Project Ideas list has been copied to the correct Project Custom fields:

image

That’s it for the simple project ideas list workflow – there is lots more that can be done but hopefully that gives you a good idea on how to get started. Next up we will take a look at getting started with the project life cycle workflow and progress a project through various stages and phases.

Blog at WordPress.com.
Entries and comments feeds.