I have member specific information I’ll need to upload for them so they do not have to repeat the entry but when the data is imported it takes the owner_id of the user importing and the owner_id cannot be changed.
Procedurally, I’d like to import all the profile information and update each profile with the correct owner as they sign up on the site. They’ll need to send me a note and I can update in the content manager. Unless there’s a better way of course.
I’m a newbie to wix code and see the previous post has been closed. I understand a hook is no longer needed and I’m not clear on the exact script for the reference mentioned in the post:
“Now it is possible to update _owner by passing suppressAuth: true option. This works only from backend code.
Examples: wixData.insert(‘collectionName’, {_owner: “11111111-1111-1111-1111-111111111111”, title: “Custom Owner”},{suppressAuth: true })
wixData.update(‘collectionName’, {_id:“existing document id”, _owner: “11111111-1111-1111-1111-111111111111”, title: “Custom Owner”},{suppressAuth: true })”
Do I create a New Web Module or .js file?
Do I need to import an API? wixData ?
The developer references “11111111…”, is this a specific id? I’ll need to update the owner_id to the one created by the user. With the wix code in place - can I update the owner_id field from the content manager? Or do I create an “Admin” page with 2 fields. I would input the old id in the first field and the new id in the 2nd field and press a button to make the change?
What would the backend code look like:
import wixData from ‘wix-data’ ;
let options = {
“suppressAuth” : true ,
“suppressHooks” : true
};
5) What would the front end code look like:
Any help would be tremendous as I’ve spent hours pouring over examples and just can’t pull this one together in my head.
you need to call from the frontend to backend, thus a .jsw file
yes, wix-data
no 1111111 is just an example. All _owner id´s are uuid (cfg3f-sdfsd-etc…)
You cannot change owner in COntent Manager. This has been requested.
4 +5) create a form with 2 fields (old val, new val). On buttton click, call a function in the jsw-file
backend something like:
export function changeOwner (oldVal, newVal){
//here: 1:query collection using oldVal and “await”-query, 2: assign .items to an array, 3:loop thru array and change _owner with newVal 4: use bulkUpdate to write whole array at once, with options set as you mentioned (suppress…)
Apologies but I’m completely new to wix code. I understand the concept but having trouble with the syntax. I’ll be updating the owner id’s one by one (as new users create their accounts) so I’ve created a page with 2 input boxes.
1.The collection is “Profiles”
2.Do I connect the first box (oldownerid) to a dataset on the page?
3.How do I replace the “00001” with the value of the 2nd box
Backend Code (changeprofileowner.jsw) import wixData from ‘wix-Data’ ;
“2.Do I connect the first box (oldownerid) to a dataset on the page?”
Yes, you could, you could fill a dropdown or something, or before the form, have a repeater with all data from collection and then select 1, it´s up to you.
“3. How do I replace the “00001” with the value of the 2nd box”. The 00001 here is the _id, not the _owner. wix-data.get() only works with an _id, so once you have done the .get(), you also have the _owner.
Put the whole data-array of this row into a var, change _owner and, if you do it 1-by-1, wix-data.insert() it (so .bulkInsert is not necessay).
You should study the docs, examples and articles more, because this is really all covered, it´s not difficult. The only non-documented part is the “change the owner”-part, but that thread you found.
So try it out, read, sweat, curse, but build the code. We are not going to write it for you, but if you run into a coding problem, we will help.