cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AtomicPete
Frequent Visitor

Patching to a SharePoint list column without a hard-coded column name

I have a need to patch to a SharePoint list. The list has multiple columns and normally in the Patch function I have to specify the name of the specific column that I want to patch to followed by a colon and then the data to patch. Example from the Microsoft help docs:

 

Patch( IceCream, Defaults( IceCream ), { Flavor: "Strawberry" } )

 

Flavor is the name of the column in the IceCream SharePoint list and the string "Strawberry" will be patched to that column in a new record. My SharePoint list has lot of Flavor columns. Flavor01, Flavor02, Flavor03 .....

 

I need to be able to patch the data to a different column depending upon other variable factors. Is there a way in the Patch function to specify the name of the SharePoint list column but with part of the name coming from a context variable or some other changeable source? E.g:  'Flavor' + 'N' : "Strawberry"  where N is a context variable that contains the last part of the column name such as '01' or '02' etc.

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@AtomicPete 
In PowerApps you cannot do dynamic column names in Patch

Example:   'Flavor' + 'N' : "Strawberry"

 

Instead, you must create a logic statement to determine what should be patched and rely on fixed names.

If(
  varFlavor=1, Patch(IceCream, Defaults(IceCream), {Flavor1="Strawberry"},
  varFlavor=2, Patch(IceCream, Defaults(IceCream), {Flavor2="Strawberry"},
  varFlavor=3, Patch(IceCream, Defaults(IceCream), {Flavor3="Strawberry"},
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

2 REPLIES 2
mdevaney
Super User
Super User

@AtomicPete 
In PowerApps you cannot do dynamic column names in Patch

Example:   'Flavor' + 'N' : "Strawberry"

 

Instead, you must create a logic statement to determine what should be patched and rely on fixed names.

If(
  varFlavor=1, Patch(IceCream, Defaults(IceCream), {Flavor1="Strawberry"},
  varFlavor=2, Patch(IceCream, Defaults(IceCream), {Flavor2="Strawberry"},
  varFlavor=3, Patch(IceCream, Defaults(IceCream), {Flavor3="Strawberry"},
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Okay no dynamic column names available. That's a nuisance as I have about 100 columns so I will have quite a long If statement. Maybe Microsoft will add this as a feature at some point.

 

Thanks

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,261)