# insertreference() and multireference fields

**URL:** <https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665>\
**Category:** Ask the community\
**Tags:** wix-members-area, question, code\
**Created:** [December 7, 2021, 10:15am UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665 "2021-12-07T10:15:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthias-dedeyn69559](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthias-dedeyn69559/32/7889_2.png) [@matthias-dedeyn69559](https://forum.wixstudio.com/u/matthias-dedeyn69559)\
**Post date:** [December 7, 2021, 10:15am UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/1 "2021-12-07T10:15:06Z")

</div>

Hi there,

I have been trying to insert the user filling in a form as a reference when he submits it. looking at the wix api I came up with the following code

```javascript
export function button2_click(event) {

    currentMember.getMember(options)
      .then((member) => 
        {

            const id = member._id;
            const loggedIn = member ? true : false;
            const loginEmail = member.loginEmail;
            const contactEmails = member.contactDetails.emails;
          
            let UserEmail = [];
            UserEmail.push(loginEmail);

            let UserID = [];
            UserID.push(id);

            console.log(UserID)

            
            let itemObj = $w("#dataset2").getCurrentItem();
            console.log(itemObj._id)

            wixData.insertReference("Members/PrivateMembersData", "test", itemObj._id , "4082af76-e744-4fe6-a025-2ca88ffc19c6")
              .then( () => {
                console.log("Reference inserted");
              } )
              .catch( (error) => {
                console.log(error);
              } );

 
            
            $w("#dataset2").save();

           
            
            $w('#text84').text = loginEmail;
            $w('#text85').text = id;
            //$w('#text91').text = val;

        })

```

this code does not work and I cat get my head around how it would know in which row the item should be referenced, I have also tried filling in the fieldkey instead of itemobj.\_id but to no evail.  
Does anyone know how to solve this issue, thank you.

---

<div class="post-metadata">

**Author:** ![jarod](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jarod/32/3202_2.png) [@jarod](https://forum.wixstudio.com/u/jarod)\
**Post date:** [December 7, 2021, 3:55pm UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/2 "2021-12-07T15:55:15Z")

</div>

You are not able to insert anything into the private members database. This is a read only database. Read more about it [here](https://support.wix.com/en/article/velo-wix-members-privatemembersdata-collection-fields)

---

<div class="post-metadata">

**Author:** ![matthias-dedeyn69559](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthias-dedeyn69559/32/7889_2.png) [@matthias-dedeyn69559](https://forum.wixstudio.com/u/matthias-dedeyn69559)\
**Post date:** [December 8, 2021, 9:54am UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/3 "2021-12-08T09:54:30Z")

</div>

Hi @jarod , I was aware of this. I am not trying to insert anything in the private members database but trying to do the opposite and linking the name to the test database. according to the api this is the way to do that or am I wrong?

---

<div class="post-metadata">

**Author:** ![jarod](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jarod/32/3202_2.png) [@jarod](https://forum.wixstudio.com/u/jarod)\
**Post date:** [December 8, 2021, 2:28pm UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/4 "2021-12-08T14:28:20Z")

</div>

Does the console throw an error message? If so what is it. Could you send the link for the form so I can test?

---

<div class="post-metadata">

**Author:** ![matthias-dedeyn69559](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthias-dedeyn69559/32/7889_2.png) [@matthias-dedeyn69559](https://forum.wixstudio.com/u/matthias-dedeyn69559)\
**Post date:** [December 8, 2021, 2:39pm UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/5 "2021-12-08T14:39:55Z")

</div>

@jarod  
nope and it even says the reference is inserted

![](https://us1.discourse-cdn.com/wix/original/3X/7/3/732fe7443395dfb509b86a2053ea8a6f7821fcbb.png)  
https ://www. byrssa. io/account /test  
this is the link but its behind a members portal

---

<div class="post-metadata">

**Author:** ![empro2pro](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/empro2pro/32/31056_2.png) [@empro2pro](https://forum.wixstudio.com/u/empro2pro)\
**Post date:** [December 9, 2021, 12:56pm UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/6 "2021-12-09T12:56:13Z")

</div>

Hi brov, did you find a solution do this?

---

<div class="post-metadata">

**Author:** ![matthias-dedeyn69559](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/matthias-dedeyn69559/32/7889_2.png) [@matthias-dedeyn69559](https://forum.wixstudio.com/u/matthias-dedeyn69559)\
**Post date:** [December 10, 2021, 2:06pm UTC](https://forum.wixstudio.com/t/insertreference-and-multireference-fields/1665/7 "2021-12-10T14:06:21Z")

</div>

@jarod  
@empro2pro

Found the solution thaks to you Jarod and with a little help of wix devs.  
to make things short, this was the actual code I need.

```javascript
            let itemObj = $w("#dataset2").getCurrentItem();
            console.log(itemObj._id)
            wixData.insertReference("test", "people", itemObj._id , member._id)

```

It basically came down to me not understanding the insertReference documentation where I thought you had to first reference the original collection, then the current collection and then both ID’s of the items. But apperantly velo has enough with the ID of the item that you want to refer. This is the original code the wx dev team gave me but this would have just created another item which I didnt want.

```javascript
The advanced department has reviewed the case and got back to us with the clarifications that you should only use insertReference() when adding items to the reference field. Insert() works with the regular reference fields instead.
Your code would look similar to this (with your own IDs and values, of course):

```

```javascript
let toInsert = {
       "title": $w('#input1').value,
   }

   wixData.insert("test", toInsert)
   .then( (results) =>{
       console.log("INSERT", results)
       wixData.insertReference("test", "people", results._id, '816f7f9a-d347-47f4-9c46-d98507fd984b')
   })

```

For the Wix team I would suggest to change the explenation of this piece of text

![](https://us1.discourse-cdn.com/wix/original/3X/3/3/336f5bc1962333deae6247bcb1ff805715a09a8d.png)

Thank you
