cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mts1
Helper III
Helper III

Update if item already exist, patch if not

Hi all,

 

Hope you are doing well.

 

I'm trying to use the lookup function inside a for all.

 

I want to update gallery items if it already exist on SP, and create a new item if it doesn't exist. in my Child Gallery i have a label where the SP ID is stored if item already exist.

 

Do you know if my requirement is possible inside a for all ? Here my OnSelect code 

 

//===Filter and Patch Child Gallery items.
ForAll(ParentGallery.AllItems,
ForAll(
    Filter(
        AddColumns(
            ChildGallery.AllItems,
            //===Add a column for sum of Calls and Emails
            "CallsAndEmailsAndInvestigationSum", Sum(Value(Prod_inptCallsHandled.Text), Value(Prod_inptEmailsHandled.Text), Value(Prod_inptInvestigation.Text)),
            //===Add a column for sum of all SL inputs
            "SLsSum", Sum(Value(Prod_inptSL1.Text), Value(Prod_inptSL2.Text), Value(Prod_inptSL3.Text), Value(Prod_inptSL4.Text))
        ),
        //===Perform check: Calls + Emails is greater than zero
        //===Perform check: Calls + Emails = Sum of SL inputs
        CallsAndEmailsAndInvestigationSum > 0 && CallsAndEmailsAndInvestigationSum = SLsSum
    ) As ChildGalleryRecord,
    		Patch(PAT_Tracker_App_DailyProductivity, Defaults(PAT_Tracker_App_DailyProductivity), 
			{'Task Date': Text(Prod_DatePicker.SelectedDate, "dd/mm/yyyy")},
			{'Agent Name': ChildGalleryRecord.lblAgentName.Text},
			{'Agent Email Address': Text(PeoplePicker.Selected.Mail)},
			{Country: ChildGalleryRecord.Prod_lblCountry.Text},
			{Exception: ChildGalleryRecord.Prod_lblException.Text},
			{Carrier: ChildGalleryRecord.Prod_lblCarrier.Text},
			{'Calls Handled': If(IsBlank(ChildGalleryRecord.Prod_inptCallsHandled.Text),0,(ChildGalleryRecord.Prod_inptCallsHandled.Text))},
            {'Calls Reached': If(IsBlank(ChildGalleryRecord.Prod_inptCallsReached.Text),0,(ChildGalleryRecord.Prod_inptCallsReached.Text))},
			{'Emails Handled': If(IsBlank(ChildGalleryRecord.Prod_inptEmailsHandled.Text),0,(ChildGalleryRecord.Prod_inptEmailsHandled.Text))},
            {Investigation: If(IsBlank(ChildGalleryRecord.Prod_inptInvestigation.Text),0,(ChildGalleryRecord.Prod_inptInvestigation.Text))},
			{'Handled SL1': If(IsBlank(ChildGalleryRecord.Prod_inptSL1.Text),0,(ChildGalleryRecord.Prod_inptSL1.Text))},
			{'Handled SL2': If(IsBlank(ChildGalleryRecord.Prod_inptSL2.Text),0,(ChildGalleryRecord.Prod_inptSL2.Text))},
			{'Handled SL3': If(IsBlank(ChildGalleryRecord.Prod_inptSL3.Text),0,(ChildGalleryRecord.Prod_inptSL3.Text))},
			{'Handled SL4 or more': If(IsBlank(ChildGalleryRecord.Prod_inptSL4.Text),0,(ChildGalleryRecord.Prod_inptSL4.Text))}
        )))
    ;

 

1 ACCEPTED SOLUTION

Accepted Solutions

@Mts1 Yes you can go with the solution which you mentioned above, I think both will work fine.

View solution in original post

4 REPLIES 4
Mts1
Helper III
Helper III

I tried to use the lookup function but it seems it's not working in my case

goel_gagandeep
Resolver I
Resolver I

Hi @Mts1 , please check, I Hope it will give you some help, take it as reference

Patch(
    TestData,
    ForAll(Gallery1.AllItems,
        With({_item: LookUp(TestData, Title = Title2.Text)},
            {
               ID: _item.ID,
               Title: Title2.Text,
               trigger: "trigger",
               temp: "1"
            }
        )
    )
)

 

HI @goel_gagandeep ,

 

Many thanks for that.

 

I found the solution by using the below code, do you think it's better to use your code for App Performance or it's the same?

 

If(
        IsEmpty(Filter(PAT_Tracker_App_DailyProductivity,ID = Value(ChildGalleryRecord.lblSPTaskID.Text))),
            Patch(PAT_Tracker_App_DailyProductivity, Defaults(PAT_Tracker_App_DailyProductivity), 
			{'Task Date': Text(Prod_DatePicker.SelectedDate, "dd/mm/yyyy")},
			{'Agent Name': ChildGalleryRecord.lblAgentName.Text},
			{'Agent Email Address': Text(PeoplePicker.Selected.Mail)},
			{Country: ChildGalleryRecord.Prod_lblCountry.Text},
			{Exception: ChildGalleryRecord.Prod_lblException.Text},
			{Carrier: ChildGalleryRecord.Prod_lblCarrier.Text},
			{'Calls Handled': If(IsBlank(ChildGalleryRecord.Prod_inptCallsHandled.Text),0,(ChildGalleryRecord.Prod_inptCallsHandled.Text))},
            {'Calls Reached': If(IsBlank(ChildGalleryRecord.Prod_inptCallsReached.Text),0,(ChildGalleryRecord.Prod_inptCallsReached.Text))},
			{'Emails Handled': If(IsBlank(ChildGalleryRecord.Prod_inptEmailsHandled.Text),0,(ChildGalleryRecord.Prod_inptEmailsHandled.Text))},
            {Investigation: If(IsBlank(ChildGalleryRecord.Prod_inptInvestigation.Text),0,(ChildGalleryRecord.Prod_inptInvestigation.Text))},
			{'Handled SL1': If(IsBlank(ChildGalleryRecord.Prod_inptSL1.Text),0,(ChildGalleryRecord.Prod_inptSL1.Text))},
			{'Handled SL2': If(IsBlank(ChildGalleryRecord.Prod_inptSL2.Text),0,(ChildGalleryRecord.Prod_inptSL2.Text))},
			{'Handled SL3': If(IsBlank(ChildGalleryRecord.Prod_inptSL3.Text),0,(ChildGalleryRecord.Prod_inptSL3.Text))},
			{'Handled SL4 or more': If(IsBlank(ChildGalleryRecord.Prod_inptSL4.Text),0,(ChildGalleryRecord.Prod_inptSL4.Text))}
        ),
        Patch(PAT_Tracker_App_DailyProductivity, LookUp(PAT_Tracker_App_DailyProductivity,ID = Value(ChildGalleryRecord.lblSPTaskID.Text)), 
			{'Calls Handled': If(IsBlank(ChildGalleryRecord.Prod_inptCallsHandled.Text),0,(ChildGalleryRecord.Prod_inptCallsHandled.Text))},
            {'Calls Reached': If(IsBlank(ChildGalleryRecord.Prod_inptCallsReached.Text),0,(ChildGalleryRecord.Prod_inptCallsReached.Text))},
			{'Emails Handled': If(IsBlank(ChildGalleryRecord.Prod_inptEmailsHandled.Text),0,(ChildGalleryRecord.Prod_inptEmailsHandled.Text))},
            {Investigation: If(IsBlank(ChildGalleryRecord.Prod_inptInvestigation.Text),0,(ChildGalleryRecord.Prod_inptInvestigation.Text))},
			{'Handled SL1': If(IsBlank(ChildGalleryRecord.Prod_inptSL1.Text),0,(ChildGalleryRecord.Prod_inptSL1.Text))},
			{'Handled SL2': If(IsBlank(ChildGalleryRecord.Prod_inptSL2.Text),0,(ChildGalleryRecord.Prod_inptSL2.Text))},
			{'Handled SL3': If(IsBlank(ChildGalleryRecord.Prod_inptSL3.Text),0,(ChildGalleryRecord.Prod_inptSL3.Text))},
			{'Handled SL4 or more': If(IsBlank(ChildGalleryRecord.Prod_inptSL4.Text),0,(ChildGalleryRecord.Prod_inptSL4.Text))}
            ))))
    ;

 

@Mts1 Yes you can go with the solution which you mentioned above, I think both will work fine.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,460)