I’m trying to retrieve an event from the event collection and then use the _id to retrieve the associated registration form but I’m running into problems with the getform.
return searchEventBackend ( slug )
. then ( ( result ) => {
$w ( ‘#eventTitle’ ). text = result . title ; return ( result );
})
. then ( eventResult => {
eventData = eventResult ;
eventId = eventData . _id ; return wixEvents . getForm ( eventId )
})
. then ( formResult => {
console . log ( formResult );
If I use return wixEvents.getForm I get Error: Request failed 401. If, on the other hand I remove the return then formResult is undefined.
It can’t be that difficult can it?
Please add more details:
backend/front end?
Show the function declaration.
What are the collection permissions?
Do you run it as Admin/member/visitor?
etc…
The code snippet is backend. searchEventBackend(slug) is a backend function to retrieve the event. WixEvents.getform(eventId) is the function to retrieve the form object.
function populateEventFields() {
return searchEventBackend( slug )
.then(result => {
$w('#eventTitle').text = result.title;
console.log(result) //WHAT DOES IT LOG? POST It HERE
return wixEvents.getForm(result._id)
})
.then(form => {
console.log(form.formData);
})
}
Thanks for that. I’ve tidied the code as you recommended but I still get Error: Request failed 401. The console.log(result) correctly displays the data from the backend search.
The only reference to an error 401 refers to not having permission to perform this action but I’m running in Preview mode and as admin. There’s no option in getForm for options so how do I ensure everyone has permission to get the form?
@jonatandor35 Thanks J.D. It used to work on both live and preview. I got a phone call to say it wasn’t working so I tried it in preview which gives this error. Weird or what?
Anyway thanks for you help