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

On Success Property with Patch logic not behaving as expected

Hi Folks -

 

Upon submitting a request (New or Edit), I have logic created on the "On Success" field which Patches or Removes values based on certain conditions (4 conditions total). 

 

I'm noticing that even when a condition is TRUE, the Patch or RemoveIf logic is not working. 

 

For instance,  I added each condition to a label which will display "false" or "true" if a condition is met just before submitting to explain the current issue.  As you can see in my screen shot below, the "second" label box is showing "true", which coincides with the second condition ("Condition 2")  in my logic:

_OnSuccess.png

 

Here is my logic:

 

If(
	// Condition 1 : Partnership Removal for child Investments
	And(!IsBlank(PTPID),IsBlank(PTPID_OC)),
		UpdateIf(
			rdInvestments,
				Mid(ProjectCode,5,5)=Mid(DataCardValue53.Text,5,5),
				{
					PartnershipID:Blank(),
					PartnershipAlias:Blank(),
					Partnered:
						{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
						Id:1, Value:"No"},
					RequestStatus:
					{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
						Id:6, Value:"On-Hold"}
				}
		),
		
	//Condition 2: Patch Asset to rdPartner_Pending Table if Partnered field = "Request Partner"
   	And(Len(LookUp(rdPartner_Pending,Title=DataCardValue53.Text,Title)) = 0,PTP_RP <> "Request Partner",PTOGGLE="Request Partner"),
		Patch( rdPartner_Pending, Defaults( rdPartner_Pending ),
			{ 
				Title: DataCardValue53.Text ,
				Data_Element_Alias: DataCardValue54.Text ,
				Requested_Date: Today() ,
				Requestor_Email: User().Email ,
				Comments: DataCardValue129.Text ,
				Requestor_Name: User().FullName
			}
		
	),
	
	//Condition 3: Ensure Asset is purged from rdPartner_Pending
	And(Len(LookUp(rdPartner_Pending,Title=DataCardValue53.Text,Title)) > 0,PTP_RP = "Request Partner",PTOGGLE<>"Request Partner"),
		RemoveIf(rdPartner_Pending,Title=DataCardValue53.Text),
		
	//Condition 4: Terminate all child Investments if Asset is Terminated
	DataCardValue35.Selected.Value ="Terminated",  
		UpdateIf(
			rdInvestments, Mid(ProjectCode,5,5)=Mid(DataCardValue53.Text,5,5),
			{
				PortfolioStatus:
				{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
					Id:10, Value:"Terminated"},
			 RequestStatus:
				{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
					Id:5, Value:"Updated"}
			}
		)
);
Concurrent(
	UpdateContext({vTitle: ""}),
	Navigate(SuccessMessage,ScreenTransition.None),
	ResetForm(AssetEditForm),
	Refresh(rdAssets),Set(PTOGGLE,Blank())
)

 

 

After submit, I am NOT seeing the results I would expect based on the patch logic.  Now, if I remove the FIRST condition, the "Condition 2" works fine if I mimic the same situation.  Why is this?  Condition two is the only TRUE condition (per my screen shot) but it doesn't seem to be executing.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@simms7400 

You should consider referencing the LastSubmit values rather than the values in your DataCard.  They are not guaranteed to be there after you submit.

I re-wrote your formula in order to identify any issues.  Here is that re-write.

If(
    // Condition 1 : Partnership Removal for child Investments
    !IsBlank(PTPID) && IsBlank(PTPID_OC)),
        UpdateIf(rdInvestments,
            Mid(ProjectCode,5,5) = Mid(Formx.LastSubmit.ProjectCode, 5, 5),
                {
                    PartnershipID:Blank(),
                    PartnershipAlias:Blank(),
                    Partnered: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"No"},
                    RequestStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"On-Hold"}
                }
        ),
		
    //Condition 2: Patch Asset to rdPartner_Pending Table if Partnered field = "Request Partner"
    Len(LookUp(rdPartner_Pending, Title=Formx.LastSubmit,Title, Title)) = 0  && 
    PTP_RP <> "Request Partner" &&
    PTOGGLE="Request Partner",
        Patch( rdPartner_Pending, Defaults( rdPartner_Pending ),
            { 
                 Title: Formx.LastSubmit.Title,
                 Data_Element_Alias: Formx.LastSubmit.Data_Element_Alias,
                 Requested_Date: Today(), 
                 Requestor_Email: User().Email,
                 Comments: Formx.LastSubmit.Comments,
                 Requestor_Name: User().FullName
            }
        ),
	
    //Condition 3: Ensure Asset is purged from rdPartner_Pending
    Len(LookUp(rdPartner_Pending, Title=Formx.LastSubmit.Title, Title)) > 0 &&
    PTP_RP = "Request Partner" &&
    PTOGGLE<>"Request Partner",
        RemoveIf(rdPartner_Pending,Title=DataCardValue53.Text),
		
    //Condition 4: Terminate all child Investments if Asset is Terminated
    Formx.LastSubmit.Status.Value ="Terminated",  
        UpdateIf(rdInvestments, Mid(ProjectCode,5,5) = Mid(Formx.LastSubmit.ProjectCode,5,5),
            {
                PortfolioStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Terminated"},
                RequestStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Updated"}
            }
        )
);


UpdateContext({vTitle: ""});
ResetForm(AssetEditForm);
Refresh(rdAssets);
Set(PTOGGLE,Blank())

Navigate(SuccessMessage,ScreenTransition.None),

 

You will notice in the formula that there are several places where it now references the Formx.LastSubmit.  I do not know the name of the Form you have or the fields that the DataCardValues that were previously referenced apply to, so you will need to adjust those to fit the scenario.

 

I also had assumed based on your logic that the complex columns are all choice columns and not lookup columns.  If so, there is no need for a Value on those.

Also took out the concurrent statement as it has no value in this instance and reordered the way those last statement should be.

 

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

4 REPLIES 4
RandyHayes
Super User III
Super User III

@simms7400 

You should consider referencing the LastSubmit values rather than the values in your DataCard.  They are not guaranteed to be there after you submit.

I re-wrote your formula in order to identify any issues.  Here is that re-write.

If(
    // Condition 1 : Partnership Removal for child Investments
    !IsBlank(PTPID) && IsBlank(PTPID_OC)),
        UpdateIf(rdInvestments,
            Mid(ProjectCode,5,5) = Mid(Formx.LastSubmit.ProjectCode, 5, 5),
                {
                    PartnershipID:Blank(),
                    PartnershipAlias:Blank(),
                    Partnered: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"No"},
                    RequestStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"On-Hold"}
                }
        ),
		
    //Condition 2: Patch Asset to rdPartner_Pending Table if Partnered field = "Request Partner"
    Len(LookUp(rdPartner_Pending, Title=Formx.LastSubmit,Title, Title)) = 0  && 
    PTP_RP <> "Request Partner" &&
    PTOGGLE="Request Partner",
        Patch( rdPartner_Pending, Defaults( rdPartner_Pending ),
            { 
                 Title: Formx.LastSubmit.Title,
                 Data_Element_Alias: Formx.LastSubmit.Data_Element_Alias,
                 Requested_Date: Today(), 
                 Requestor_Email: User().Email,
                 Comments: Formx.LastSubmit.Comments,
                 Requestor_Name: User().FullName
            }
        ),
	
    //Condition 3: Ensure Asset is purged from rdPartner_Pending
    Len(LookUp(rdPartner_Pending, Title=Formx.LastSubmit.Title, Title)) > 0 &&
    PTP_RP = "Request Partner" &&
    PTOGGLE<>"Request Partner",
        RemoveIf(rdPartner_Pending,Title=DataCardValue53.Text),
		
    //Condition 4: Terminate all child Investments if Asset is Terminated
    Formx.LastSubmit.Status.Value ="Terminated",  
        UpdateIf(rdInvestments, Mid(ProjectCode,5,5) = Mid(Formx.LastSubmit.ProjectCode,5,5),
            {
                PortfolioStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Terminated"},
                RequestStatus: {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Value:"Updated"}
            }
        )
);


UpdateContext({vTitle: ""});
ResetForm(AssetEditForm);
Refresh(rdAssets);
Set(PTOGGLE,Blank())

Navigate(SuccessMessage,ScreenTransition.None),

 

You will notice in the formula that there are several places where it now references the Formx.LastSubmit.  I do not know the name of the Form you have or the fields that the DataCardValues that were previously referenced apply to, so you will need to adjust those to fit the scenario.

 

I also had assumed based on your logic that the complex columns are all choice columns and not lookup columns.  If so, there is no need for a Value on those.

Also took out the concurrent statement as it has no value in this instance and reordered the way those last statement should be.

 

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 

 

Hi Randy, I hope you have been well.  Long time no talk, I still owe you that beer (or 2) when you come to Boston! 🙂

 

With that said, thank you very much for your help here. I was able to make the updates and it's working as expected now. I do have a few questions..

 

1.  How come changing the And to && worked? Why wouldn't And logic work, isn't it doing the same thing?

2. Can you elaborate on the LastSubmit functionality and why it's preferred in this situation? I can't quite wrap my head around it.

 

Thank you!

@simms7400 

Yes indeed, still waiting to get to Boston for those beers!  I hope you have been well also.

 

So, it wasn't so much changing the And's to &&, that was a byproduct of my re-writing the formula.  In this case, either one would have been just fine.  It was just easier for me to read the formula as I went through it - just a personal pref.

 

However, the LastSubmit is the key.  When you submit a form, the datacardvalues (the controls tied to fields in your EditForm) may change.  This is either from Resetting the form, the FormMode you have for default or any of a number of other obscure situations.  However, the LastSubmit is a full record of the last record submitted by the Form.  It will NOT change until you submit again.  So, instead of referencing controls which might change (the DataCardValue controls), the key is to reference the LastSubmit values, as they will remain.

 

I hope that is clear (and perhaps worth another beer 😉 )

 

 

_____________________________________________________________________________________
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

@RandyHayes 

 

Thank you for the explanation. That makes perfect sense!

 

I have went through all of my other forms and updated them accordingly based on this.  Thank you again!

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

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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 (1,343)