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

If condition is not working as expected!

Hello,

 

My objective is as follows:

 

If EditForm mode == Edit, then do nothing

If EditForm mode == New, then create a record

 

Therefore, I have written following formula:

If(EditForm.Mode=FormMode.Edit,"",Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})); --> It's not working

If(EditForm.Mode=FormMode.New,Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})); -->It's not working

 

Can you please share where I am wrong here?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
dave8
Impactful Individual
Impactful Individual

While checking on this further, I see that If condition is not working because:

 

FormMode is returning "0" value if FormMode == New and Edit, there is no differentiation between New and Edit, therefore if condition is not working out.

 

Therefore, now I have declared variable called EditFormMode, if NewForm mode is navigated, then EditFormMode = 1, If Edit form mode is navigated then EditFormMode = 0

 

and using the following formula, which is working as expected:

 

If((EditFormMode = 1),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'}))

 

Thank you!

 

View solution in original post

4 REPLIES 4
KrishnaV
Super User
Super User

Hi @dave8 ,

 

Try this:

If(!(yourformanem.Mode = FormMode.Edit),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'}))

If((yourformanem.Mode = FormMode.Edit),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'}));

 


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
dave8
Impactful Individual
Impactful Individual

Hi @KrishnaV 

 

Both are not working as it should:

 

If(!(yourformanem.Mode = FormMode.Edit),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})) - This doesn't patch, if FormMode is New

If((yourformanem.Mode = FormMode.Edit),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})); - This does patch regardless if FormMode is Edit


While my requirement is, It should only patch if FormMode = New

 

I then try with following formulas:

If(!(yourformanem.Mode = FormMode.New),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})) - This does patch regardless if FormMode is New

 

If((yourformanem.Mode = FormMode.New),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'})) - This does note patch if FormMode is New

 

How do I patch ONLY if form mode == New?
 
Thanks,

dave8
Impactful Individual
Impactful Individual

While checking on this further, I see that If condition is not working because:

 

FormMode is returning "0" value if FormMode == New and Edit, there is no differentiation between New and Edit, therefore if condition is not working out.

 

Therefore, now I have declared variable called EditFormMode, if NewForm mode is navigated, then EditFormMode = 1, If Edit form mode is navigated then EditFormMode = 0

 

and using the following formula, which is working as expected:

 

If((EditFormMode = 1),Patch('Updates',Defaults('Updates'),{'Status':'In Progress'}))

 

Thank you!

 

Since that the issue is resolved please mark the relevant reply as a solution so that it will help the new members in the community. 


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,551)