Hi all, I’m trying to write to a collection created with the permission type set to “Form submission”. I have the following code:
BACK END
export function setPerson (i d , person Id )
{
return wixData . get ( “person_data” , i d )
. then ( ( item ) =>
{
let options = {
“suppressAuth” : true ,
“suppressHooks” : true
};
item .person Id = person Id ;
wixData . update ( “person_data” , item , options );
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );
}
FRONT END
setPerson (id, person Id )
. then ( ( results ) => {
} )
. catch ( ( error ) =>
{
}
)
All this works perfectly in PREVIEW mode, but in the published site nothing happens. What am I doing wrong?
Is that your whole code, which is involved into the issue?
-Where is your IMPORT ???
-Why not declaring the permissions-options just right from the beginning of your function? Or even declaring them global?
Front-End-Code:
import {setPerson} from 'backend/xxxxxxxxxxxxx.jsw'
$w.onReady(function () {
setPerson(id, personId).then((results)=> {console.log(results);});
);}
Backend-Code:
export function setPerson(id, personId){
let options = {
"suppressAuth": true,
"suppressHooks": true
};
return wixData.get("person_data", id)
.then((item)=> {
item.personId = personId;
wixData.update("person_data", item, options);
}).catch((err)=>{return err;});
}
And when comparing now your optimized code, with an example of the UPDATE-API, still something is missing?
let toUpdate = {
6 "_id": "00001",
7 "title": "Mr.",
8 "first_name": "John",
9 "last_name": "Doe"
10};
11
12wixData.update("myCollection", toUpdate)
13 .then( (results) => {
14 let item = results; //see item below
15 } )
16 .catch( (err) => {
17 let errorMsg = err;
18 } );
It’s still working like a charm in preview mode, but not in the published website. My question here is, why can we only give a read-only or write-only permission (mutually exclusive) on form-driven collections? If I have a form that feeds a collection, I may want to edit the content at a later date. Why can’t we give a form-driven collection read/write permissions?
Likewise, I’m trying to read the data from the same form-driven collection and the code works beautifully in preview mode, but not on the published website.
FONT END:
import { getDetail } from ‘backend/detail.jsw’ ;
$w . onReady ( function ()
{
getDetail ( “00001” )
. then ( ( result ) => {
} )
. catch ( ( err ) => {
} );
} );
BACK END:
export function getDetail ( id )
{
return wixData . query ( “person_data” )
. eq ( “_id” , id )
. find ({ “suppressAuth” : true })
}
Currently, the collection’s permissions are set to “Form Submission”. If I set them to “Site Content”, the above works fine, but I can no longer submit the data from the form. The permissions seem to be mutually exclusive and I can’t find ones that allow for both read AND write functions.
Why don’t you use “Custom use” on the Collection’s Settings and set every action individually?
Thank you, thank you, thank you!!! It worked.