web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Dataverse low code plu...
Power Apps
Unanswered

Dataverse low code plugin - how to patch a lookup column on ThisRecord?

(0) ShareShare
ReportReport
Posted on by 20

I want to set a lookup column on ThisRecord using an automated low code plugin. Say I select the Student table and I want to set the teacher column (which is a lookup to Teacher table) for ThisRecord to simply be the first teacher on the Teachers table . From a canvas app, I might have this code: 

 

 

Set('Main Teacher', First(Teachers))

 

 

 

But when I put that in the plug-in I get an error that "This record cannot be copied. Instead, create an inline record using {...} notation to copy the individual fields desired." with the First function underlined in red.

 

I tried their suggestion by recreating the full record inside {...} but then was getting error "Invalid argument type (Record). Expecting a Record value instead.".

 

I also tried to use the Relate function in Power Fx to set the lookup but even though it's not listed on the Formulas not currently supported with low code plug-ins, I get the error "'Relate' is a recognized but not supported function." .  

 

How do I set/patch a column of type lookup on ThisRecord? 

I have the same question (0)
  • Ostritch Profile Picture
    20 on at

    UPDATE

    I managed to use Patch for the Create event:

    Patch(Students,ThisRecord,{'Main Teacher':First(Teachers)})

    But I still think I need to use Set in Update event to avoid an infinite loop...

  • NT-23070621-0 Profile Picture
    on at

    I think you can try:
    But be notice that Lookup will return table type and the Patch function's second parameter is a Record data type.
    Patch(
    <Your Collection>,
    <Lookup Result Record>,
    {<Your field>: <Your Value>}
    );


  • autopower Profile Picture
    45 on at

    Yes, wrt to Patch the documentation does indeed state in the Best Practices section that:

     

    Don't write a patch statement on an automated plugin upon 'Update' event, where the patch is happening on the same table as the plugin. This leads to infinite loops and plugin execution failures.

    Problematic pattern: Using Patch() formula triggers another update.

    Did you find any other way to set a lookup (without using Set or Patch)?

  • Suggested answer
    Mark Nanneman Profile Picture
    991 Super User 2025 Season 2 on at
    I spent hours trying to get a low-code plugin to update a lookup column--the error messages in the formula advisor are not that helpful!  I finally figured out that by "inline record" it's refering to the With() function, but when you use the "With" function it seems like you have to use a Patch--at least that's how I could get it to work.  I had to create "inline records" for both the current record and the related/lookup record. 

    So this is how you'd need to do it in your case:
     
    With(
        {
          vThisRecord: NewRecord,
          vTeacherLookup: First(Teachers)
         },
    
         Patch(Students,vThisRecord, {'Main Teacher': vTeacherLookup})
    )


    I documented how I set lookups for a plugin I was working on in a blog post here:
    Use With() to Set Lookup Column with Low-Code Automated Plugin in Dataverse Accelerator – Power Stuff
  • ronaldwalcott Profile Picture
    3,847 Super User 2025 Season 2 on at
    The Patch should not cause an infinite loop when run in the created, but it would run whatever code is in the updated since it triggers an update.
     
    The infinite loop would occur in the updated because a Patch triggers an update which would then run what is in the updated which is a patch and so on and so on.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 759 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 310 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 228

Last 30 days Overall leaderboard