web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Canvas App wont proces...
Power Apps
Unanswered

Canvas App wont process second IF statement

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

It will process this first IF statement fine, but does not proceed to the second to Patch the "INBOUND" portion. This connects to two separate SharePoint lists. Someone please help!!!!

 

If(!IsBlank(B211OUTBOUND.Selected.Railcar),
 If( (StatusToggleB211.Value=false), 
 Patch('374 Staged',
 LookUp('374 Staged', Railcar = B211OUTBOUND.Selected.Railcar),
 {Track: "B211", Status: {Value: "MT"}, Railcar: ""}
 );
 Patch('374 MECL',
 LookUp('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar),
 {Spot: {Value: "OUTBOUND"}}, {Status: {Value: "MT"}}, {'Last Movement': Today()} 
 );,
 Patch('374 MECL',
 LookUp('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar),
 {Spot: {Value: "YARD"}}, {Status: {Value: "FULL"}}, {'Last Movement': Today()} 
 );
 Patch('374 Staged',
 LookUp('374 Staged', Railcar = B211OUTBOUND.Selected.Railcar),
 {Track: "B211-1", 
 Status: {Value: "MT"},
 Railcar: ""}
 );
 );
);

If(!IsBlank(B211INBOUND.Selected.Railcar),
 Patch('374 Staged',
 LookUp('374 Staged', Track = "B211-1"),
 {Railcar:B211INBOUND.Selected.Railcar, 
 Status: {Value:"FULL"}}
 );
 Patch('374 MECL',
 LookUp('374 MECL', Railcar = B211INBOUND.Selected.Railcar),
 {Spot: {Value: "B211-1"}}
 );
);

 

Categories:
  • BCLS776 Profile Picture
    8,994 Moderator on at

    I don't see anything obviously wrong, but I have a troubleshooting tip: Try putting an error message in the "else" side of your second If() statement to see if that's where the condition is taking it:

    If(!IsBlank(B211INBOUND.Selected.Railcar),
     Patch('374 Staged',
     LookUp('374 Staged', Track = "B211-1"),
     {Railcar:B211INBOUND.Selected.Railcar, 
     Status: {Value:"FULL"}}
     );
     Patch('374 MECL',
     LookUp('374 MECL', Railcar = B211INBOUND.Selected.Railcar),
     {Spot: {Value: "B211-1"}}
     );,
     Notify("There was an error")
    );

    Also, you said the first If() statement was working correctly, but the condition on the nested If() could be simplified to: 

    If( (!StatusToggleB211.Value), 
     Patch('374 Staged',

    which treats it truly like a boolean value.

     

    Hope that helps,

    Bryan

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello,

     

    When i ran this code snipped above, it actually changed all values in the list to the same railcar number/spot/status. 

     

    Previously I was using this code - but could not get it to also go past the first IF statement. 

     

    If(!IsBlank(B211INBOUND.Selected.Railcar),
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar:B211INBOUND.Selected.Railcar, 
     Status: {Value:"FULL"}}
     );
     Patch('374 MECL',
     LookUp('374 MECL', Railcar = B211INBOUND.Selected.Railcar),
     {Spot: {Value: "B211-1"}}
     );
     UpdateContext( {B211IN: B211INBOUND.Selected.Railcar})
    
    );
    If( !IsBlank(B211OUTBOUND.Selected.Railcar) && !StatusToggleB211.Value,
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
     UpdateContext( {B211OUT: B211OUTBOUND.Selected.Railcar});
     Set( B211STAT, false);
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "MT"}, 
     Spot:{Value: "OUTBOUND"}
     }
     ),
     ! IsBlank(B211OUTBOUND.Selected.Railcar),
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "FULL"},
     Spot:{Value: "YARD"}
     }
     );
     UpdateContext( {B211OUT: B211OUTBOUND.Selected.Railcar});
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
    );

     

    I appreciate you taking the time to review this - i am really lost at what im doing wrong 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Maybe something to do with how i have this IF And statement put together? really confused - the syntax seems right to me-

    If( !IsBlank(B211OUTBOUND.Selected.Railcar), And(StatusToggleB211.Value=false),
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
     Set( B211STAT, false);
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "MT"}, 
     Spot:{Value: "OUTBOUND"}
     }
     );
     ! IsBlank(B211OUTBOUND.Selected.Railcar),
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "FULL"},
     Spot:{Value: "YARD"}
     }
     );
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
    );

      

  • BCLS776 Profile Picture
    8,994 Moderator on at

    Whenever I have problems with logical statements like this, I start by simplifying them so I can understand the logic flow. Then, once I am confident the logic works correctly, I add the functionality back in one piece at a time to make sure it works. Use /* and */ to inactivate blocks of code and replace them with some other indicator of functionality, such as a Notify(). To help with debugging, I frequently add temporary labels with Text properties containing some of the same conditions in the code: 

    !IsBlank(B211INBOUND.Selected.Railcar)

    That way, there is a visual indicator of the true/false condition going into the If() statement. From a set of those, you will be able to see the logic flow through your statement upon execution.

     

    An important note about If() statements: the logic flow breaks out of the statement as soon as a condition matches - further conditions are not evaluated. So for a statement such as:

    If(conditionA, resultA, conditionB, resultB, defaultresult)

    If conditionA and conditionB are both true, only resultA is returned. The If() statement stops executing after returning the first true result. 

     

    An important note about UpdateIf() statements: as a table operation, it changes every record that matches the condition. If the condition shows true for every row, then every row will get changed.

     

    Without seeing your data and being able to evaluate each expression myself, it's tough for me to say where your logical error is. However, the info above should help you isolate and find it. Try it out.

    Bryan

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you for the reply, 

     

    What would be the best way to go about the logic i am looking for? 

     

    I feel like I have tried If / And/ Or and all of these have not worked for me

     

    Basically trying to check if the dropdown is not empty and then checking what the user sets the toggle at, then update the two lists based on their selection. I really am not sure the best way to do this...

     

    johnc222_0-1634238424114.png

     

     

  • BCLS776 Profile Picture
    8,994 Moderator on at

    OK, when I look at this code there is an issue:

    If( !IsBlank(B211OUTBOUND.Selected.Railcar), And(StatusToggleB211.Value=false),
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
     Set( B211STAT, false);
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "MT"}, 
     Spot:{Value: "OUTBOUND"}
     }
     );
     ! IsBlank(B211OUTBOUND.Selected.Railcar),
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "FULL"},
     Spot:{Value: "YARD"}
     }
     );
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
    );

    You can't have two conditions at the start of an If() statement. Instead try:

    If( !IsBlank(B211OUTBOUND.Selected.Railcar) && !StatusToggleB211.Value,
     // both conditions will need to be true for the If() to choose the first result

     

    Does your app have only two choices for how to handle the user input? If so, remove the second condition from the If() statement and force anything that does not match the first condition into the default result:

    If( !IsBlank(B211OUTBOUND.Selected.Railcar) && StatusToggleB211.Value,
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
     Set( B211STAT, false);
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "MT"}, 
     Spot:{Value: "OUTBOUND"}
     }
     );
     , // no need for a second condition if everything else gets handled by the default
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "FULL"},
     Spot:{Value: "YARD"}
     }
     );
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
    );

    Bryan

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you so much Bryan for your help - when i enter your suggestion for the two values,

    the && symbol becomes grayed out - is this a concern at all? I believe I previously had this set this way but i didnt think it was working? 

     

    johnc222_0-1634239724251.png

     

  • BCLS776 Profile Picture
    8,994 Moderator on at

    @Anonymous wrote:

    Thank you so much Bryan for your help - when i enter your suggestion for the two values,

    the && symbol becomes grayed out - is this a concern at all? I believe I previously had this set this way but i didnt think it was working? 

     

    johnc222_0-1634239724251.png

     


    That's no issue - that indicates Power Apps is recognizing the && characters as the AND operator.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Okay so after finnicking around with this for a bit - it is working ( somewhat ) but removing the second if statement as you suggested forces it to basically wipe the change immediately after when it gets to this point 

    If(!IsBlank(B211INBOUND.Selected.Railcar),
     Patch('374 Staged',
     LookUp('374 Staged', Track = "B211-1"),
     {Railcar: B211INBOUND.Selected.Railcar},
     {Status: {Value:"FULL"}} <<<<<PATCHES CAR IN
     );
     Patch('374 MECL',
     LookUp('374 MECL', Railcar = B211INBOUND.Selected.Railcar),
     {Spot: {Value: "B211-1"}}
     );
    
    );
    If( !IsBlank(B211OUTBOUND.Selected.Railcar) && !StatusToggleB211.Value, 
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}}
     );
     Set( B211STAT, false);
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "MT"}, 
     Spot:{Value: "OUTBOUND"}
     }
     );
     , <<<< REMOVED THE IF STATEMENT HERE
     UpdateIf('374 MECL', Railcar = B211OUTBOUND.Selected.Railcar,
     {Status: {Value: "FULL"},
     Spot:{Value: "YARD"}
     }
     );
     UpdateIf('374 Staged', Track = "B211-1",
     {Railcar: "", Status: {Value:"MT"}} <<< OVERWRITES THE EARLIER PATCH BACK TO BLANK
     );
    );
  • BCLS776 Profile Picture
    8,994 Moderator on at

    With my little understanding of the business logic that underlies your app, I notice you have two completely independent If() statements, one for Inbound and one for Outbound. They share no condition terms, so their decisions don't depend on one another. The only thing controlling one, both, or neither statement from running are the conditions in each statement. 


    To link their behavior, you may need to use nested If() statements. Or, you may need to include more terms to the conditions in the existing If()s that include the terms common to the other dropdown. It depends on the business logic.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard