Good morning,
I have run into an obstacle. I have a large database (dbCompanies). It contains descriptive information about companies in our community. The user selects companies of research interest and adds them to their portfolio. There is a temporary database (tmpDbSelect) that serves as interim repository while they scroll down a long list of Cos and select/deselect research candidates.
They can then click Add Selected Cos to Portfolio and the button will populate the dbSelectedCompanies database, which contains the fields User, SelectCompanies, and a reference field to the larger database dbCompanies.
I was having difficulty adding the reference field. I attempted insertReference, but through research in this forum, I learned that it only works with multi reference fields, and that I should use insert but insert the _id of the reference company’s record in the larger database (dbCompanies).
So I created a query before the .insert segment in order to retrieve the record _id from the larger database. When I test the retrieval, I get the message:
WDE0025: The dbCompanies collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.
I know that the database is there. I don’t know how to approach a solution here and would truly appreciate any assistance.
Please see the code below and thank you in advance.
export function btnAddSelectCo_click ( event ) {
var nbrCosAdded ;
var refField ;
var tempCo ;
wixData . query ( "tmpDbSelect" )
. find ()
. then ( **async** ( results ) => {
nbrCosAdded = results . items . length ;
**for** ( **let** i = 0 ; i < results . items . length ; i ++) {
tempCo = results . items [ i ]. selectedCompanies ;
//console.log(tempCo);
**await** wixData . query ( "dbCompanies" )
. eq ( "userSelectedCompanies" , tempCo )
. limit ( 1 )
. find ()
. then (( res ) => {
refField = res . items [ 0 ]. _id ;
});
**await** wixData . insert ( "dbSelectedCompanies" , {
"userId" : activeUserId ,
"upliftId" : userUpId ,
"userSelectedCompanies" : tempCo ,
"referenceCompany" : refField
})
. then (() => {
$w ( "#txtCompaniesAdded" ). text = "Companies added." ;
$w ( "#txtCompaniesAdded" ). show ();
});
}
})
}