Hi, I need some help. I am trying to teach myself to code, but I have trouble with async functions.
I am trying to query our custom database and label all who meet the criteria. Query results length is 155, but only 100 or so get labeled. I think the function needs more time, but I don’t get how to do it.
front end code:
import wixData from ‘wix-data’ ;
import { LabelforMailing } from ‘backend/contacts.jsw’ ;
async function filterResults ( low , high ) {
if ( $w ( “#dropdown8” ). value ) {
**await** wixData . query ( "Membership" )
. eq ( "memberStatus" , $w ( "#dropdown8" ). value )
. limit ( 1000 )
. find ()
. then ( ( results ) => {
**if** ( results . items . length > 0 ) {
**let** items = results . items ;
console . log ( results . items . length );
**for** ( **let** i = 0 ; i < results . items . length ; i ++) {
**let** item = results . items [ i ];
**let** mailingId = item . title ;
console . log ( mailingId );
LabelforMailing ( mailingId )
}
}
})
}
}
export function button48_click ( event ) {
filterResults ()
}
backend code:
import { contacts } from ‘wix-crm-backend’ ;
export async function LabelforMailing ( mailingId ) {
const contactId = mailingId ;
const labelKey = [
“custom.todays-mailing”
];
const options = {
suppressAuth : true
};
await contacts . labelContact ( contactId , labelKey , options )
. then (( labeledContact ) => {
return labeledContact ;
})
. catch (( error ) => {
console . error ( error );
});
}