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

Patch Inside ForAll not working

Hi,

 

For some reason, a patch function inside a ForAll is not working and not throwing error, all the data are presented, but no request is being made, this is a full-function

UpdateContext({varIsLoading_MS: true});

ForAll(
    colAgreements,
    Patch(
        [@Agreements],
        LookUp(
            colAgreements,
            Agreement = colAgreements[@Agreement]
        ),
        {'System Status': 'Agreement System Status'.Active}
    );
    
);

UpdateContext({varIsLoading_MS: false});

and this is the data inside colAgreements

2020-05-19_11-43-30.png

but still, this is the only call that I'm getting once I click the button2020-05-19_11-44-52.png 

any ideas ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Patch Inside ForAll not working

Hi @aboodhamwi ,

 

OK, maybe the Button.OnSelect is inside the gallery? Whatever, it seems the ForAll loop works well, but the option set value is not saved. please try to add disambiguity operator around the option set name 'Agreement System Status'.

UpdateContext({varIsLoading_MS: true});

ForAll(
    RenameColumns(colAgreements,"Agreement","AgreementID")
    Patch(
        [@Agreements],
        LookUp(
            [@Agreements],
            Agreement = AgreementID
        ),
        {'System Status': [@'Agreement System Status'].Active}
    );
    
);

UpdateContext({varIsLoading_MS: false});

 

I find you only want to save the constant value('Agreement System Status'.Active) to some records of entity, the UpdateIf function could be more suitable. If the ForAll function still doesn't work, please try this:

UpdateContext({varIsLoading_MS: true});
UpdateIf([@Agreements], Agreement in colAgreements.Agreement,{'System Status': [@'Agreement System Status'].Active});
UpdateContext({varIsLoading_MS: false});

 Hope this helps.

Sik

View solution in original post

8 REPLIES 8
Highlighted
Community Support
Community Support

Re: Patch Inside ForAll not working

Hi @aboodhamwi ,

 

The issue is caused by source error of LookUp function. The source should be Agreements instead of colAgreements.

Please try this:

UpdateContext({varIsLoading_MS: true});

ForAll(
    colAgreements,
    Patch(
        [@Agreements],
        LookUp(
            Agreements,
            Agreement = colAgreements[@Agreement]
        ),
        {'System Status': 'Agreement System Status'.Active}
    );
    
);

UpdateContext({varIsLoading_MS: false});

Hope this helps.

Sik

Highlighted
Helper III
Helper III

Re: Patch Inside ForAll not working

@v-siky-msft ,

for some reason, I will get Delegation warning, the Agreements is a CDS entity

2020-05-19_13-39-47.png

Highlighted
Community Support
Community Support

Re: Patch Inside ForAll not working

Hi @aboodhamwi ,

 

Since the Agreement field is GUID field, the workaround is to rename its column name in collection to avoid ambiguity.

Please try this:

UpdateContext({varIsLoading_MS: true});

ForAll(
    RenameColumns(colAgreements,"Agreement","NewColumnName")
    Patch(
        [@Agreements],
        LookUp(
            Agreements,
            Agreement = NewColumnName
        ),
        {'System Status': 'Agreement System Status'.Active}
    );
    
);

UpdateContext({varIsLoading_MS: false});

Sik

 

Highlighted
Helper III
Helper III

Re: Patch Inside ForAll not working

@v-siky-msft ,

 

Now it's showing it's looping but the patch is not being called

2020-05-19_14-24-59.png

 

Highlighted
Community Support
Community Support

Re: Patch Inside ForAll not working

Hi @aboodhamwi ,

 

Where does the code apply? Why does it need a Disambiguity operator around the Agreements?

Could you please to remove the Disambiguity operator and try again? 

Sik

 

Highlighted
Helper III
Helper III

Re: Patch Inside ForAll not working

@v-siky-msft ,

For some reason, I will get an error if I remove it, I don't know how this works and why sometimes the platform will do this

2020-05-20_8-45-31.png

Highlighted
Community Support
Community Support

Re: Patch Inside ForAll not working

Hi @aboodhamwi ,

 

OK, maybe the Button.OnSelect is inside the gallery? Whatever, it seems the ForAll loop works well, but the option set value is not saved. please try to add disambiguity operator around the option set name 'Agreement System Status'.

UpdateContext({varIsLoading_MS: true});

ForAll(
    RenameColumns(colAgreements,"Agreement","AgreementID")
    Patch(
        [@Agreements],
        LookUp(
            [@Agreements],
            Agreement = AgreementID
        ),
        {'System Status': [@'Agreement System Status'].Active}
    );
    
);

UpdateContext({varIsLoading_MS: false});

 

I find you only want to save the constant value('Agreement System Status'.Active) to some records of entity, the UpdateIf function could be more suitable. If the ForAll function still doesn't work, please try this:

UpdateContext({varIsLoading_MS: true});
UpdateIf([@Agreements], Agreement in colAgreements.Agreement,{'System Status': [@'Agreement System Status'].Active});
UpdateContext({varIsLoading_MS: false});

 Hope this helps.

Sik

View solution in original post

Highlighted
Helper III
Helper III

Re: Patch Inside ForAll not working

@v-siky-msft ,

This resolved the issue 🙂

[@'Agreement System Status']

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (5,192)