cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DAVIDPOWELL
Post Prodigy
Post Prodigy

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 III
Super User III

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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

2 REPLIES 2
RandyHayes
Super User III
Super User III

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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

@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
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 is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (33,192)