Dear all,
- Complete newbie here-
After interesting days of learning on the Velo resource pages, and reading the fora here.
I am still a bit stuck and would love for the community to give me a push in the right direction.
What I am trying to do is i assume simple:
Make a drop-down list on a front-end page, showing the Company name of the contacts.
Stored under info.company in the wix-crm-backend. The label should be the company name, the value of either the company name or the _ID.
Now I assume I have understood the concept of working:
A: Make a .jsw that runs on the backend > That calls for this information.
B: Import the .JSW into the front end, and use the called information
A: I have thus ( with help of the Velo resources) made a .jsw, with a Query that calls for all the information in { contacts } from ‘wix-crm-backend’, ordered: .ascending (“info.company”)
Testing it in the Console this works. Here is the Cod
Back end
import { contacts } from ‘wix-crm-backend’ ;
export function QueryContactsFunction ( ) {
return contacts . queryContacts ()
. ascending ( “info.company” )
. find ()
. then (( results ) => {
if ( results . items . length > 0 ) {
const items = results . items ;
return items ;
} else {
// Handle case where no matching items found
}
})
. catch (( error ) => {
console . error ( error );
})
Where I get stuck is what happens on the front end ( I assume).
I think I am not pointing to the correct information, or don’t understand yet how.
here is the code:
Front End.
import { QueryContactsFunction } from ‘backend/GetMemberInfo.jsw’
$w . onReady ( async () => {
$w ( “#ClientSelectDropdown” ). options =
const query = await QueryContactsFunction
. query ( “items” )
. ascending ( “info.company” )
. find ()
**const** queryItems = query . items
$w ( "#ClientSelectDropdown" ). options = prepareContactsForDropdown ( queryItems , "info.company" )
})
function prepareContactsForDropdown ( data , info . company ) {
return data . map ( item => {
return {
label : item [ info . company ],
value : item [ info . company ],
}
})
}
}
Can anyone tell me where my error is? Or what logic I did not understand yet?
Thanks