cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

If statement conditions not executing correctly

Here is the If statement:

 

If(
      IsBlank(txtExtraTotalHours),
      Notify("Please enter total hours."),
      IsBlank(txtExtraComments),
      Notify("Please enter a comment."),
      Value(txtExtraTotalHours.Text) > difference,
      Notify("Total hours can not exceed the total hours between the selected dates. Please choose a correct total              hours option."),
      Set(
            varExtraIncrement,
            varExtraIncrement + 1
      ),
      Reset(txtExtraTotalHours) && Reset(txtExtraComments),
      Collect(
                  DowntimeRecords,
                    {
                      BusAreaColl: txtExtraBusinessArea.Text,
                      CountryColl: dpdExtraCountry.SelectedText.Value,
                      LocationColl: dpdExtraLocation.SelectedText.Value,
                      AffectedSystemColl: txtExtraAffectedSystem.Text,
                      StartDateColl: txtExtraStartDate.Text,
                      EndDateColl: txtExtraEndDate.Text,
                      TotalHoursColl: txtExtraTotalHours.Text,
                      TowerColl: txtExtraTower.Text,
                      CommentsColl: txtExtraComments.Text,
                      IncidentNumberColl: txtExtraIncidentNumber.Text,
                      UpdatedByColl: txtExtraUpdatedBy.Text,
                      RecordNumberColl: txtExtraRecNumber.Text
                    }
                 )
 );

 

The last two conditions, Reset the text inputs and the Collect function aren't working correctly. If I put the Reset code below the Collect code, the Collect function works but the text inputs don't reset, and vice versa. For some reason, whatever the default condition is in this If statement, it won't execute. Any ideas as to where I am going wrong would be great. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Anonymous ,

Based on the formula that you mentioned, I think there is somthing wrong with it. In addition, you could not put the Reset(...) formula before the Collect(...) function.

If you put the Reset(...) formula before the Collect(...) function, when the Reset(...) function is executed, the txtExtraTotalHours.Text formula and txtExtraComments.Text formula would return blank, then when you execute the Collect function, it would save blank value to your TotalHoursColl column and CommentsColl column in your DowntimeRecords collection.

 

I have made a test on my side, please consider modify your formula as below:

 

If(
      IsBlank(txtExtraTotalHours),
      Notify("Please enter total hours."),
      IsBlank(txtExtraComments),
      Notify("Please enter a comment."),
      Value(txtExtraTotalHours.Text) > difference,
      Notify("Total hours can not exceed the total hours between the selected dates. Please choose a correct total hours option."),
      Set(
            varExtraIncrement,
            varExtraIncrement + 1
      );         /* <-- Type ; rather than , */
      Collect(
                  DowntimeRecords,
                   {
                      BusAreaColl: txtExtraBusinessArea.Text,
                      CountryColl: dpdExtraCountry.SelectedText.Value,
                      LocationColl: dpdExtraLocation.SelectedText.Value,
                      AffectedSystemColl: txtExtraAffectedSystem.Text,
                      StartDateColl: txtExtraStartDate.Text,
                      EndDateColl: txtExtraEndDate.Text,
                      TotalHoursColl: txtExtraTotalHours.Text,
                      TowerColl: txtExtraTower.Text,
                      CommentsColl: txtExtraComments.Text,
                      IncidentNumberColl: txtExtraIncidentNumber.Text,
                      UpdatedByColl: txtExtraUpdatedBy.Text,
                      RecordNumberColl: txtExtraRecNumber.Text
                    }
        );        /* <-- Type ; rather than ,  */
Reset(txtExtraTotalHours); /* <-- Put your Reset(...) formula here */
Reset(txtExtraComments) /* <-- Put your Reset(...) formula here */ )

Note: The '&&' operator used to join multiple Logic condition. The ; operator used to separate invocations of functions in behavior properties. Please check this article for more details about the difference between ; (formula chain) and && (Logic operators).

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
K-A-R-L
Solution Specialist
Solution Specialist

Hi @Anonymous ,

 

Are you trying to reset the TextInput Field once a collection is created?

Please change your code to:

If(
      IsBlank(txtExtraTotalHours),
      Notify("Please enter total hours."),
      IsBlank(txtExtraComments),
      Notify("Please enter a comment."),
      Value(txtExtraTotalHours.Text) > difference,
      Notify("Total hours can not exceed the total hours between the selected dates. Please choose a correct total 
hours option."), Set( varExtraIncrement, varExtraIncrement + 1 ), Collect( DowntimeRecords, { BusAreaColl: txtExtraBusinessArea.Text, CountryColl: dpdExtraCountry.SelectedText.Value, LocationColl: dpdExtraLocation.SelectedText.Value, AffectedSystemColl: txtExtraAffectedSystem.Text, StartDateColl: txtExtraStartDate.Text, EndDateColl: txtExtraEndDate.Text, TotalHoursColl: txtExtraTotalHours.Text, TowerColl: txtExtraTower.Text, CommentsColl: txtExtraComments.Text, IncidentNumberColl: txtExtraIncidentNumber.Text, UpdatedByColl: txtExtraUpdatedBy.Text, RecordNumberColl: txtExtraRecNumber.Text } ) ); If(!IsBlank(txtExtraTotalHours) && !IsBlank(txtExtraComments),Reset(txtExtraTotalHours) && Reset(txtExtraComments))

----------------------------------------------------------------------------
Thanks,
K-A-R-L


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If you thought this post was helpful, please give it a Thumbs Up.

SkiDK
Solution Sage
Solution Sage

I think it could be the structure you're writing it in. The if statement goes as followed:

 

If( Condition1, ThenResult1 [, Condition2, ThenResult2, ... [ , DefaultResult ] ] )

Only the last one is a default which should be executed. I suppose you're last three lines (Set, Reset and Collect) should be part of the default. The function will now see the Set function as an If statement and the Reset function as the code to run when the Set is ture, and else the Collect fucntion will run.

 

You'll have to put these all in one block after the comma for the default if you want all of them to run by putting in a ';' for a new line of code:

 

If(
      IsBlank(txtExtraTotalHours),
      Notify("Please enter total hours."),
      IsBlank(txtExtraComments),
      Notify("Please enter a comment."),
      Value(txtExtraTotalHours.Text) > difference,
      Notify("Total hours can not exceed the total hours between the selected dates. Please choose a correct total              hours option."),
      Set(
            varExtraIncrement,
            varExtraIncrement + 1
      );
      Reset(txtExtraTotalHours) && Reset(txtExtraComments);
      Collect(
                  DowntimeRecords,
                    {
                      BusAreaColl: txtExtraBusinessArea.Text,
                      CountryColl: dpdExtraCountry.SelectedText.Value,
                      LocationColl: dpdExtraLocation.SelectedText.Value,
                      AffectedSystemColl: txtExtraAffectedSystem.Text,
                      StartDateColl: txtExtraStartDate.Text,
                      EndDateColl: txtExtraEndDate.Text,
                      TotalHoursColl: txtExtraTotalHours.Text,
                      TowerColl: txtExtraTower.Text,
                      CommentsColl: txtExtraComments.Text,
                      IncidentNumberColl: txtExtraIncidentNumber.Text,
                      UpdatedByColl: txtExtraUpdatedBy.Text,
                      RecordNumberColl: txtExtraRecNumber.Text
                    }
                 )
 );

 Could you see if this works?

Anonymous
Not applicable

Hi @K-A-R-L 

 

Yes, the default conditions once all other error handling has been checked are Set, Reset and Collect. By concatenating these into a single default condition, could I use && between each of these? 

 

I will try your solution and see if it works. Thanks!

The && is for conditions, to see if this AND that is true. To run the next line of code is to simply put ';' after each line. 

v-xida-msft
Community Support
Community Support

Hi @Anonymous ,

Based on the formula that you mentioned, I think there is somthing wrong with it. In addition, you could not put the Reset(...) formula before the Collect(...) function.

If you put the Reset(...) formula before the Collect(...) function, when the Reset(...) function is executed, the txtExtraTotalHours.Text formula and txtExtraComments.Text formula would return blank, then when you execute the Collect function, it would save blank value to your TotalHoursColl column and CommentsColl column in your DowntimeRecords collection.

 

I have made a test on my side, please consider modify your formula as below:

 

If(
      IsBlank(txtExtraTotalHours),
      Notify("Please enter total hours."),
      IsBlank(txtExtraComments),
      Notify("Please enter a comment."),
      Value(txtExtraTotalHours.Text) > difference,
      Notify("Total hours can not exceed the total hours between the selected dates. Please choose a correct total hours option."),
      Set(
            varExtraIncrement,
            varExtraIncrement + 1
      );         /* <-- Type ; rather than , */
      Collect(
                  DowntimeRecords,
                   {
                      BusAreaColl: txtExtraBusinessArea.Text,
                      CountryColl: dpdExtraCountry.SelectedText.Value,
                      LocationColl: dpdExtraLocation.SelectedText.Value,
                      AffectedSystemColl: txtExtraAffectedSystem.Text,
                      StartDateColl: txtExtraStartDate.Text,
                      EndDateColl: txtExtraEndDate.Text,
                      TotalHoursColl: txtExtraTotalHours.Text,
                      TowerColl: txtExtraTower.Text,
                      CommentsColl: txtExtraComments.Text,
                      IncidentNumberColl: txtExtraIncidentNumber.Text,
                      UpdatedByColl: txtExtraUpdatedBy.Text,
                      RecordNumberColl: txtExtraRecNumber.Text
                    }
        );        /* <-- Type ; rather than ,  */
Reset(txtExtraTotalHours); /* <-- Put your Reset(...) formula here */
Reset(txtExtraComments) /* <-- Put your Reset(...) formula here */ )

Note: The '&&' operator used to join multiple Logic condition. The ; operator used to separate invocations of functions in behavior properties. Please check this article for more details about the difference between ; (formula chain) and && (Logic operators).

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Thank you @v-xida-msft , @SkiDK  and @K-A-R-L  for your help. The semicolon solution worked well. I appreciate it! 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,432)