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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Moving records from on...
Power Apps
Answered

Moving records from one identical Sharepoint to another

(0) ShareShare
ReportReport
Posted on by 37

Hello all, I have a relatively simple question. I have two Sharepoint lists that are identical, the idea is that once someone opts out of one list we save that record to another for record keeping and delete the original one. I have grabbed the record and put it into a variable and have confirmed it is the correct one. I have also successfully deleted the one one (Last line of code shown). But the second line is the problem, after I get the record, it does not show up in the second list. I have tried Defaults() as the second parameter but with no luck, I feel like I'm missing something obvious. I'd like to do this record move without a flow if possible.

 

Thanks!

 

 

Set(moveRecord, LookUp('WkShp Registration List', Email_x0020_Address.Email = VarUserEmail &&'Session ID'.Value = varParentItem.SessionID));

 

Patch('WkShp UnRegistration List', Defaults('WkShp UnRegistration List'), moveRecord);

 

Remove( 'WkShp Registration List', First(Filter( 'WkShp Registration List', Email_x0020_Address.Email = VarUserEmail && 'Session ID'.Value = varParentItem.SessionID)));

 

 

(again it's "onlyPatch('WkShp UnRegistration List', Defaults('WkShp UnRegistration List'), moveRecord);" that seems to be not working)

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    155,779 Most Valuable Professional on at

    Hi @TheNewGuyAtWork ,

    Have you looked at moveRecord (view > variables) to see what is in it? Also how many fields are in the record?

  • TheNewGuyAtWork Profile Picture
    37 on at

    I have not, I see that is is a function in Powerapps, but I can't find info in the docs about it. There are 19 fields I believe, both Sharepoint's are identical. Also what are the arguments for the function? Nothing about moveRecord seems to come up when I google.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I'm not sure PowerApps will understand the Defaults() function in your second argument of Patch(). I've never actually used that method. I prefer to explicitly rebuild my record when patching from one table into another. So, in your case, I'd try this...

    Patch(
     'WkShp UnRegistration List',
     {
     Email_x0020_Address: moveRecord.Email_x0020_Address,
     Session_ID: moveRecord.Session_ID
     },
     moveRecord
    )

    If that record already exists in the WkShp UnRegistration List, then it will be replaced with moveRecord. If it doesn't exist, then a new record will be created with the information in moveRecord.

     

    At least, that's how I understand it should work. I actually abandoned SharePoint lists a while ago for use with PowerApps, because they were a real pain to work with. Instead, I set up SharePoint libraries that store all the information I would have used in lists with a combination of JSON files and folder structure.

  • TheNewGuyAtWork Profile Picture
    37 on at

    This helps a lot, I think I've just about got it, this is what I have:

    Patch(
    'WkShp UnRegistration List',
    {
    Email_x0020_Address: moveRecord.Email_x0020_Address.Email,
    Session_x0020_ID_x003a_Title : moveRecord.'Session ID:Title'.Value
    },
    moveRecord
    );

     

    Some of the info I needed is in complex field types, so the email is actually in moveRecord.Email_x0020_Address.Email. I ran into something similar when doing a collection but I'm still unsure how to lay it out based on that. The error is "The type of this argument  Email_x0020_Address does not match the expected type "Record" Found Type "Text" and "the patch function has invalid arguments". The thing is if I give it a record it's a complex field type and won't get the data it needs

     

    There is actually a lot of fields in the table I'm trying to place this into, but these are really the main two I need.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    That error makes sense, because the field Email_x0020_Address in SharePoint is an object (you can tell, because it has a set of properties associated with it), and you're trying to put a text value (Email_x0020_Address.Email) into it. Instead, try identifying the record using the entire email address object.

    Email_x0020_Address: moveRecord.Email_x0020_Address

    Another option is to compare the Email property of each object (both text values).

    Email_x0020_Address.Email: moveRecord.Email_x0020_Address.Email
  • TheNewGuyAtWork Profile Picture
    37 on at


    'WkShp UnRegistration List',
    {
    Email_x0020_Address: moveRecord.Email_x0020_Address,
    Session_x0020_ID_x003a_Title : moveRecord.'Session ID:Title'
    },
    moveRecord
    );

     

     

    I tried to just pass in the records, this code works but upon checking the Sharepoint list no records appear when I use the button to submit. When using both with .Email and .Value respectively they produce an error. I'm not sure why it wouldn't error but not put anything into the list.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    After reading through the doc for the Patch() function, it looks like you really are supposed to use the Defaults() function as the second argument to create a new record—I've never done it that way, but I guess that's the official way to do it. So, your original expression should have worked.

     

    I wonder if there is some really obscure difference between the lists. Did you create the WkShp UnRegistration List using SharePoint's "create from another list" functionality? If not, you'd have to go through all the list settings with a fine-toothed comb to make sure everything's identical.

    Screenshot 2021-04-09 155513.png

     

    Another possible solution might be to create the new record not using a copy of the original, but only using those fields which are present in the original record. That is...

    Patch(
     'WkShp UnRegistration List',
     Defaults('Wk UnRegistration List'),
     {
     Email_x0020_Address: moveRecord.Email_x0020_Address,
     Field2: Value2,
     Field3: Value3,
     etc...
     }
    )

     This would essentially force SharePoint to create the new record using defaults, and then replace only those fields you specify (which would be everything in moveRecord, if you list them all). Just make sure all your data types match between record values.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Just thought of something. If the SharePoint list field ID is contained in your moveRecord record, then that might also be why it's failing when you try to pass the entire record in the third argument. You can't explicitly set the ID field, since that's unique and auto-generated in all SharePoint lists.

  • TheNewGuyAtWork Profile Picture
    37 on at

    I have a feeling this is the actual issue, honestly is there a way to disregard that one field? Or at least set it to auto generate?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    It will auto-generate in the new list, anyway (and it won't be the same as the ID in the other list). The only way to avoid it would be to explicitly list the other (settable) fields explicitly in the third argument. As I said earlier, I've never tried creating a new list item by passing the entire record from another list, so I don't even know if you can do it that way. You might need to always explicitly name fields in that third argument so as to avoid things like the ID field.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 477

#2
WarrenBelz Profile Picture

WarrenBelz 341 Most Valuable Professional

#3
11manish Profile Picture

11manish 317

Last 30 days Overall leaderboard