cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DAVIDPOWELL
Impactful Individual
Impactful Individual

use a IF condition before making a Patch and alert error

I have a patch statement below,

What I need:

#1 -- I need to make sure a textbox(txt_Track) has a value in it(not blank/null etc..)

before executing the patch.

#2 -- If the "txt_Task" isBlank,  throw an error statement(Notify).cancel patch 

 

This should work, but need notify:

If(!IsBlank(Trim(txt_TrackCode.Text)), Patch(
t_nsc_trackcode_assigned_DataEntry,
Defaults(t_nsc_trackcode_assigned_DataEntry),
{

ID_Racfid: lbl_Racfid.Text,
Track_Code: txt_TrackCode.Text,
Seller_Name: txt_TC_Name.Text,
Director_Name: txt_Director.Text,
Track_Name: txt_TC_Name.Text,
Opened_Date: DateTimeValue(txt_OpenedDate.Text),
Expected_Completed_Date: DateTimeValue(txt_Expected_Completed_Date.Text),
Status: dwn_Status.Selected.Value,
Originated_From: "Field",
Notes: rte_Notes.HtmlText,
Activity_Task: dwn_Tasks.Selected.Activities_and_Tasks,
Col_Id_Template: dwn_Tasks.Selected.Column_ID,
Expedited:If(chk_Expedite.Value = true,"YES","NO"),
subcategory_id: dwn_SubTasks.Selected.SubCat_ID
}
);
Reset(chk_Csp_SalesForce);
Reset(chk_Csp_Quote);
Reset(cbo_ComboSearch);
Reset(txt_TrackCode);
Reset(txt_TC_Name);
Reset(txt_Seller);
Reset(txt_Director);
Reset(rte_Notes);
Reset(dwn_Tasks);
Reset(dwn_Status);
Notify("Track Added",NotificationType.Success,2000));

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

Hi @DAVIDPOWELL 

 

You might want to consider a different approach to this.  While in traditional applications the method was to allow the user to hit a button and then tell them everything they did wrong, with PowerApps (and Apps in general), a more modern method is to limit the ability for the user to press the button in the first place.

So perhaps set the DisplayMode property on your submit button to the following:

If(IsBlank(Trim(txt_TrackCode.Text)), Disabled, Edit)

The button would not be enabled unless the field is complete.

You could then also emphasize the "required" aspect of the txt_TrackCode to the user as they fill in the information. 

 

Also, a little bonus if you like...in regard to all your Reset functions.

You might consider using this little handy practice.

1) Put a Toggle control on your screen (you probably would want to make it not Visible) Let's call it tglResetForm

2) Set the OnCheck formula of the toggle to the following:  UpdateContext({resetForm:false})

3) Set the Default property of the toggle to the following: resetForm

4) Now, for all of your Controls that you want to reset, set the their Reset property to tglResetForm.Value

 

Pull all the Reset functions out of your original formula and put in a UpdateContext({resetForm:true})

 

Anytime you set the resetForm variable, it will reset all the controls that "subscribe" (via the Reset property) to that toggle.

 

Makes it handy when your form starts to grow and you have to constantly go back to modify the formulas where you have the Resets.

Just a little extra.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User
Super User

Hi @DAVIDPOWELL 

 

You might want to consider a different approach to this.  While in traditional applications the method was to allow the user to hit a button and then tell them everything they did wrong, with PowerApps (and Apps in general), a more modern method is to limit the ability for the user to press the button in the first place.

So perhaps set the DisplayMode property on your submit button to the following:

If(IsBlank(Trim(txt_TrackCode.Text)), Disabled, Edit)

The button would not be enabled unless the field is complete.

You could then also emphasize the "required" aspect of the txt_TrackCode to the user as they fill in the information. 

 

Also, a little bonus if you like...in regard to all your Reset functions.

You might consider using this little handy practice.

1) Put a Toggle control on your screen (you probably would want to make it not Visible) Let's call it tglResetForm

2) Set the OnCheck formula of the toggle to the following:  UpdateContext({resetForm:false})

3) Set the Default property of the toggle to the following: resetForm

4) Now, for all of your Controls that you want to reset, set the their Reset property to tglResetForm.Value

 

Pull all the Reset functions out of your original formula and put in a UpdateContext({resetForm:true})

 

Anytime you set the resetForm variable, it will reset all the controls that "subscribe" (via the Reset property) to that toggle.

 

Makes it handy when your form starts to grow and you have to constantly go back to modify the formulas where you have the Resets.

Just a little extra.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
DAVIDPOWELL
Impactful Individual
Impactful Individual

@RandyHayes ,

That worked well and thanks for the reply ! and yes that is a better suggestion.

Still getting used to the simplicity of the methods and properties and how to utilize them.

and appreciate the bonus extra help !!

 

Dave

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (4,282)