cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jesenavaranjan
Level: Powered On

Filter formula error

I'm getting an error when using IF statements within a patch? Is this not allowed? The error I get is 'Invalid ArgumentType' but does not underline or show me anything else.

 

Patch(
    '[dbo].[tbLink]',
    {LinkID: Value(LinkID)},
    {AssignedDate: DCR_1.SelectedDate},
    {AssignedUser: User.Text},
    {LinkComment: Comment.Text},
    {SourceID: 1},
    {TargetID: 1},
    {
        Type: Text(
            If(
                Type.Text = "Related to",
                "Related",
                "Parent-Child"
            )
        )
    })


Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Filter formula error

@LRVinNC  actually, yes, you can use the If statement and many others within the Patch function without having to wrap them like the samples.  This I do in many apps, it's a necessity as there are many conditions that need to be accounted for with the columns!

 

@jesenavaranjan 

Your formula, at a a glance, seems to be fine, so there is either something going on with the definition of some of those items or something impacting the designer.

I would however, make a change to the formula to be the following:

Patch(
    '[dbo].[tbLink]',
    {LinkID: Value(LinkID),
     AssignedDate: DCR_1.SelectedDate,
     AssignedUser: User.Text,
     LinkComment: Comment.Text,
     SourceID: 1,
     TargetID: 1,
     Type: If(Type.Text = "Related to", 
                "Related",
                "Parent-Child")
     }
)

Try the above formula and see if you still have the issue.  

If so, try to narrow it down.  If you suspect issues in the If statement, then first, change the "Type.Text" to "true".  If the problem goes away, then there is an issue with the Type.Text.  If not, then replace the whole If statement with one value - let's say "Related", and see if the issue still exists.

Hopefully one of the above will lead you to a clue or a solution.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Super User
Super User

Re: Filter formula error

@KroonOfficeSol 

Good call!  In my haste to look at the "If" part, totally glossed over the sourceRecord parameter missing!  Kind of think that would be helpful Smiley Wink

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Filter formula error

No, you cannot use the If within the Patch, but you can wrap the Patch statement in an If to accomplish this. 

This could be like the case in this post, https://powerusers.microsoft.com/t5/Expressions-and-Formulas/Patch-With-Conditions/td-p/107780, where you want to set a value and use that value in your patch or it could be a situation like the example code shown in the question on this post https://powerusers.microsoft.com/t5/Expressions-and-Formulas/Patch-with-if/td-p/171724 where you want to actually make your Patch statement vary slightly based on an If.  

 

Super User
Super User

Re: Filter formula error

@LRVinNC  actually, yes, you can use the If statement and many others within the Patch function without having to wrap them like the samples.  This I do in many apps, it's a necessity as there are many conditions that need to be accounted for with the columns!

 

@jesenavaranjan 

Your formula, at a a glance, seems to be fine, so there is either something going on with the definition of some of those items or something impacting the designer.

I would however, make a change to the formula to be the following:

Patch(
    '[dbo].[tbLink]',
    {LinkID: Value(LinkID),
     AssignedDate: DCR_1.SelectedDate,
     AssignedUser: User.Text,
     LinkComment: Comment.Text,
     SourceID: 1,
     TargetID: 1,
     Type: If(Type.Text = "Related to", 
                "Related",
                "Parent-Child")
     }
)

Try the above formula and see if you still have the issue.  

If so, try to narrow it down.  If you suspect issues in the If statement, then first, change the "Type.Text" to "true".  If the problem goes away, then there is an issue with the Type.Text.  If not, then replace the whole If statement with one value - let's say "Related", and see if the issue still exists.

Hopefully one of the above will lead you to a clue or a solution.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Super User
Super User

Re: Filter formula error

@RandyHayes I learn something new (usually LOTS of something new) every day.  Thanks!

KroonOfficeSol
Level 10

Re: Filter formula error

@jesenavaranjan 

 

I'm also missing the second argument for the patch. Updated from the formula of @RandyHayes 

Patch(
    '[dbo].[tbLink]',
Defaults( '[dbo].[tbLink]'),
    {LinkID: Value(LinkID),
     AssignedDate: DCR_1.SelectedDate,
     AssignedUser: User.Text,
     LinkComment: Comment.Text,
     SourceID: 1,
     TargetID: 1,
     Type: If(Type.Text = "Related to", 
                "Related",
                "Parent-Child")
     }
)

Maybe that's the reason for the error.

 

Still an error, then maybe one of the columns is not plain text, but an object. This could be the case when SharePoint is your data source?

 

Btw, in the formula bar, you don't always get a good error message. Sometimes the error message on the red marker on the canvas is more informative. You can see this by hover over the red marker. So you can try this.

 

Hope this helps also.

 

Paul

Super User
Super User

Re: Filter formula error

@KroonOfficeSol 

Good call!  In my haste to look at the "If" part, totally glossed over the sourceRecord parameter missing!  Kind of think that would be helpful Smiley Wink

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 197 members 3,180 guests
Please welcome our newest community members: