Giter Club home page Giter Club logo

automate_powerautomateflowtest's Introduction

Automate your Flowtest with CLI for Microsoft 365

This script was created for flows with SharePoint Online triggers.

Use-Case

The flow under test in this example represents an approval process. In this case the flow triggers when an item is created or modified in the sharepoint list 'demolist'.

List view

Depending on the stored metadata of the list column "requestlevel" the flow runs through different actions. This distinction is implemented by a switch statement. The flow is build like this:

Flow build

When the flow finished the enduser get a notification to take action. At this point the user has to edit the sharepoint metadata which we do with a button on the sharepoint form. So in this case we know which metadata are modified by the user.

Preperation: Adjusting the script to your use case

Create Testdata

"m365 spo listitem add"

function createTestData{
    <#
    * ADD YOUR TESTMETADATA
    * Customize this part to your system / testdata
    * trigger elements of flow runs that are not included to your testdata are not monitored
    * alternativ: just return the itemId's of manual created testdata
    #>
    $i = 0
    $testMetadata = @()

    do{
        $testMetadata += m365 spo listitem add --contentType 'Item' --listTitle $spListTitle --webUrl $spSiteUrl --Title "Test-Item $i" --RequestLevel "Started"
        $i++
    }until($i -eq 10)   

    return $testMetadata.id
}

Simulate User Input

# ----------------------------- in my case i need to get the current request level 
# based on spColoumn : requestlevel
$currentRequestLevel = $flowRunInformation.triggerInformation.requestlevel.Value


# Here you need to put your different update actions which simulated your user input to the sharepoint item
switch($currentRequestLevel){
    'Started'{
        m365 spo listitem set --listTitle $spListTitle --id $itemId --webUrl $spSiteUrl --Genehmigungslevel 'Editing'
    }
    'Editing'{
        m365 spo listitem set --listTitle $spListTitle --id $itemId --webUrl $spSiteUrl --Genehmigungslevel 'Approval'
    }
    'Approval'{
        m365 spo listitem set --listTitle $spListTitle --id $itemId --webUrl $spSiteUrl --Genehmigungslevel 'Release'
    }
    'Release'{
        # this is the last step -> so there is nothing to do
    }
}

Start the Script

Start the script in your editor (VS Studio or PowerShell ISE) or run it from your commandline

 .\automate_flowtest.ps1 -environment '<Your Environment ID>' -flow '<FlowID or DisplayName>' -spSiteUrl '<URL of our SharePoint Site' -spListTitle '<DisplayName of your list>'

Review your test

The monitoring of the flow runs are stored in an endless loop. If you finished your test wait a few minutes (get yourself a new coffee) and just end the script run. Execute the following code to "review" your test:

# run this for feedback, when you are finished 

Write-Output ("Total flowruns : {0}`n "-f $flowRunsCount)
Write-Output ("succeded flowruns : {0} `n"-f $successFlowRunsCount)
Write-Output ("canceled flowruns : {0} `n"-f $CancelledFlowRunsCount)
Write-Output ("failed flowruns : {0} `n"-f $failedFlowRunssCount)

Using: CLI for Microsoft 365

Since the Version 6.7 CLI for Microsoft 365 the command "m365 flow run get" return all the triggerInformation while using the parameter "-includetriggerInformation". With this command you can directly relate between flowrun and trigger item like a modified sharepoint list item.

npm i -g @pnp/cli-microsoft365

More about CLI for Microsoft 365

Author
Joshua Probst

automate_powerautomateflowtest's People

Contributors

joshua-probst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.