Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Trigger Condition not working

Posted on 5 Nov 2024 18:50:56 by 69
Hi everyone,
 
I am building a flow with a trigger condition that must meet two conditions before it runs from a SharePoint list but it's not working for me!  Any help would be much appreciated.
 
It should only equal one of the 3 offices (choice field) AND where the start date field is blank (date field).
 
@and(or(equals(triggerOutputs()?['body/BusinessArea']?['Value'], 'London'), equals(triggerOutputs()?['body/BusinessArea']?['Value'], 'Leeds'), equals(triggerOutputs()?['body/BusinessArea']?['Value'], 'Manchester')), equals(triggerOutputs()?['body/ConfirmedStartDate'], null))
Thanks in advance
 
C
  • rzaneti Profile Picture
    rzaneti 3,175 on 26 Nov 2024 at 22:25:31
    Trigger Condition not working
    Hi  smodkins,
     
    I just want to confirm if you have any additional questions about this issue.
     
    If everything is working properly, please mark my solution post as Accepted Answer, so other users with the same issue can find it easily in the future :)
     
     
    -------------------------------------------------------------------------
     
  • rzaneti Profile Picture
    rzaneti 3,175 on 19 Nov 2024 at 11:43:00
    Trigger Condition not working
    Hi and sorry for the late response,
     
    The current trigger expression is ignoring any record changes where the new value for the Start Date column is empty. This is managed by the contains expression in @and(or(equals(triggerOutputs()?['body/Office']?['Value'], 'London'), equals(triggerOutputs()?['body/Office']?['Value'], 'Leeds'), equals(triggerOutputs()?['body/Office']?['Value'], 'Manchester')), contains(triggerOutputs()?['body'], 'ConfirmedStartDate')).
     
    In summary, the solution may ignore the changes when a date is removed from the column :)
  • smodkins Profile Picture
    smodkins 69 on 15 Nov 2024 at 13:50:08
    Trigger Condition not working
    Thank you for coming back to me on this! 
     
    Would the proposed solution work trigger if the value was updated to empty?  We would not want it to trigger if a date was removed and it was empty.
  • rzaneti Profile Picture
    rzaneti 3,175 on 15 Nov 2024 at 01:33:48
    Trigger Condition not working
    Hi @smodkins,
     
    I'm glad to hear that it's working fine! About your question, if your idea is to have a simple process for the changes in the existing start date, you can integrate it into this same flow, by simply allocating another Condition the If no block. In this new Condition, you must test if the start date from the trigger is not equal to the  previous_date_value variable, and allocate your logic withing the If yes block:
     
     
     
    If your process for the changes in the existing start dates is complex or longer than a few steps, I would recommend you to clone the flow and change the condition for capturing the difference between the current and previous values for the column. 
     
    Let me know if it works for you or if you need any additional help!
    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.
     
  • smodkins Profile Picture
    smodkins 69 on 14 Nov 2024 at 21:13:16
    Trigger Condition not working
    Hi @rzaneti,
     
    You sir are a genius! Thank you for you help!
     
    I did have the "accept": "application/json" in but when I copied and pasted from here the accept had a rogue space after it! 
     
    My last question to you, would you incorporate a change in start date within the same flow or in a separate flow with a similar action and how would we go about this?
     
    Thanks
    smods
  • rzaneti Profile Picture
    rzaneti 3,175 on 11 Nov 2024 at 22:59:00
    Trigger Condition not working
    Hi @smodkins,
     
    Did you include the "accept": "application/json" in the headers of your Send an HTTP Request action? This error usually happens when you miss this header. 
     
    If you did include it, can you please share an image of your Send an HTTP Request action inputs, and the raw outputs from it? If you don't know how to access the raw outputs, refer to this tutorial
  • smodkins Profile Picture
    smodkins 69 on 11 Nov 2024 at 20:54:51
    Trigger Condition not working
     Hi rzanetic
     
    Sorry I didn't get to look at your response until today.  I failed at the Send HTTP request but I missed the _ in front of the api so that step is now successful
     
    The next step of initialize variable keeps failing with the error:
     
    Action 'Initialize_variable_2' failed: Unable to process template language expressions in action 'Initialize_variable_2' inputs at line '0' and column '0': 'The template language expression 'outputs('Send_an_HTTP_request_to_SharePoint')?['body']['value'][1]['ConfirmedStartDate']' cannot be evaluated because property 'value' doesn't exist, available properties are 'd'. Please see https://aka.ms/logicexpressions for usage details.'.
     
     I did as you said with replacing the outputs('Send_an_HTTP_request_to_SharePoint_-_All_versions')?['body'] with the dynamic content
     
    Thanks
    C
  • Suggested answer
    rzaneti Profile Picture
    rzaneti 3,175 on 08 Nov 2024 at 02:42:43
    Trigger Condition not working
    Hi smodkins,
     
    I have all set :)
     
    I had to work with some assumptions for this tutorial, so if something doesn't match exactly to your use case, let me know and I will be happy in provide you with further support. 
     
    Knowledge base
    Before we get started, I will share the link for some blog posts that I wrote about the topics discussed here. It can be useful for you or for any other user that finds this thread in the future.
    - How to work with Power Automate expressions: http://digitalmill.net/2024/02/27/writing-expressions-in-power-automate/
     
    List overview
    For this step-by-step, I'm working with the following SP List:
     
    Similarly to yours, it has a Office column (choice data type) and a ConfirmedStartDate column (date only). 
     
    Starting the flow: trigger and conditions
    Here I'm working with a When an item or a file is modified trigger, which capture only the updates in your SP List (and not the insertion of new items). Based on your previous posts in this thread, the flow must be triggered only when a date is assigned to a List Item, and its previous value is blank, so we don't need to capture the creation of new items:
     
    As a trigger condition, I'm using @and(or(equals(triggerOutputs()?['body/Office']?['Value'], 'London'), equals(triggerOutputs()?['body/Office']?['Value'], 'Leeds'), equals(triggerOutputs()?['body/Office']?['Value'], 'Manchester')), contains(triggerOutputs()?['body'], 'ConfirmedStartDate')), which is the same recommended in my first message, but without the not. This condition will capture only changes in items where Office is set as Leeds, London or Manchester, and the ConfirmedStartDate is not blank (after the modification). 
     
    If you are copying the condition from this step-by-step, make sure to change the "Office" column name. 
     
    Get all item versions
    For this solution, we will need to access all previous versions from the List Item, so we can compare the new one with the existing before the change. For that, we will use a HTTP request like below:
     
     
    About the request:
    - Make sure to set the Site Address as the same where your List is located.
    - Set the method to GET.
    - Use the following URI: _api/web/lists/getbytitle('Employee onboarding')/items([ID_dynamic_content])/versions/, replacing the text in red for your List name and the text in blue for the trigger's ID dynamic content.
    - Add the header accept with the value as application/json.
     
    This HTTP request will return a history of all values that your List Item ever had in its previous versions. For example, when running the flow for a modification in the "Spiderr man" record from the List, the HTTP outputs will include all values from its previous versions, including the 2.0, when the ConfirmedStartDate was blank (null):
     
     
    Getting the ConfirmedStartDate from previous version
    A good thing from this HTTP request is that it retrieves all versions as an array of objects in descending order by modification date, so you will have the current version (the just changed one) as first element, the previous version (the one from where we want to capture the ConfirmedStartDate to test if it's empty) as second element, and so on. 
     
    Having said that, we are sure that the previous version will always be allocated at the second position in the array, so we don't need to waste time comparing the different versions to identify which one is the correct. 
     
    So let's extract the form the second array element and store it into a variable. You can use the expression 
    outputs('Send_an_HTTP_request_to_SharePoint_-_All_versions')?['body']['value'][1]['ConfirmedStartDate'] for that:
     
    When copying/pasting the expression, make sure to replace outputs('Send_an_HTTP_request_to_SharePoint_-_All_versions')?['body'] for the dynamic content of the body property of your HTTP request action.
     
    Test if ConfirmedStartDate in previous version is blank
    Finally, let's test if the ConfirmedStartDate before the Item modification is blank. For that, you will need to add a condition, and set the left input as an empty expression, such as empty(variables('previous_date_value')) (make sure to use your actual variable dynamic content within the empty parentheses), keep the dropdown as is equal to and set the right input as true:
     
    The rest of your flow must now be positioned within the If yes block, since it will be executed only if the previous date was blank.
     
    Testing the flow
    I just added a new record to the List, allocated to one of the Offices that must be captured by the flow. This event, however, won't trigger the flow, since we are monitoring only modifications and not item creations: 
     
    Now let's make a small change in the name (but not in the date), which will update the Item version to 2.0, but still won't trigger the flow, since the ConfirmedStartDate is still empty:
     
    Then we will make another change (going to version 3.0), and at this time setting the date: 
     
     
    At this time, the flow finally ran, since we match both trigger conditions (Office is Leeds/London/Manchester and ConfirmedStartDate is not empty). As expected, the Condition returned as true, since the ConfirmedStartDate for version 2.0 was empty:
     
     
    If we now make any other change to the same Item, the flow will still run, but the condition will return as false, as the previous version doesn't have the ConfirmedStartDate as empty:
     
     
    Let me know if it works for you or if you need any additional help!
    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.
  • rzaneti Profile Picture
    rzaneti 3,175 on 06 Nov 2024 at 23:10:08
    Trigger Condition not working
    Hi smodkins,
     
    In this case, the HTTP request is the best path! Tomorrow I won't have so much time, but give me until Friday and I will be back here with a step-by-step on how to implement it in your flow. 
  • smodkins Profile Picture
    smodkins 69 on 06 Nov 2024 at 19:13:18
    Trigger Condition not working
    Hi rzaneti,
     
    Thank you for coming back to me.  
     
    Based on your last message, the only scenario that you want to capture is whenever the Confirmed Start Date of a record is modified from "blank" to some valid value. Is this correct?
    Exactly this! 
     
    Another option is to add a calculated column to your SP List of yes/no type, with a formula to be filled as yes only when Confirmed Start Date is not blank. With this logic, your column will change only once: whenever the Confirmed Start Date changes from blank to any valid value. In PA, you would be able to track the columns that changed with Get changes for an item and file (properties only), and since this yes/no column is automatically changed only when a date is assigned, you will simply need to track if the yes/no property changed. 
    I think the issue with this approach is I was also hoping to expand on it in the future where if the confirmed start date changes value from one date to another that it triggers a different flow informing a series of users such as line manager etc that the start date has changed so this approach would not work for that right?
     
    Happy to work with any suggestions you have
     
    Thanks
    C
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,129

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,797

Leaderboard