Dataset Entry question

Hi, I have a question about dataset entries, I’m building a website that advertises for old cars and has a fetch function from a 3rd party api that stores the required information about the vehicle into a dataset that all works.

Then the user will be asked some questions about the vehicle and will press a submit button once finished, that will enter the answers to the questions into the same dataset.

The problem is I’m getting 2 different entries into the dataset 1 will have the details from the fetch and 1 will have the answers from the questions, is there anyway to delay the fetch results from being entered into the dataset until the questions have been answered and the submit button has been pressed?

Many thanks for any help.

Please post your code + explain how you submit the form (via dataset or wixData.insert? by code or by connecting the from to the dataset via the editor UI?)

Hi, thanks for the reply, this is where I’m going wrong by having the fetch on the wixData.insert in the code and then the questions are being submitted by a button, but just don’t know if there is a way to make it so that the fetch returns the data but will only insert it into the dataset when the next step (questions) has been completed and the submit button has been pressed


//VRMLOOKUPAPI
export function buttonFMV_click ( event ) {
vrmLookup($w ( “#inputVRM” ). value . toUpperCase ())
. then (( data ) => {
$w ( ‘#VrmDetails’ ). text = "Year: " + data.Response.DataItems.VehicleRegistration.YearOfManufacture + ‘\n’ +
"Make: " + data.Response.DataItems.VehicleRegistration.Make + ‘\n’ +
"Model: " + data.Response.DataItems.VehicleRegistration.Model + ‘\n’ +
"Engine: " + data.Response.DataItems.SmmtDetails.NominalEngineCapacity + " " + data.Response.DataItems.SmmtDetails.FuelType + ‘\n’ +
"Transmission: " + data.Response.DataItems.VehicleRegistration.Transmission + ‘\n’ +
"Body Style: " + data.Response.DataItems.SmmtDetails.BodyStyle

        $w ( '#vehicleMModel' ). text  =  data.Response.DataItems.VehicleRegistration.Make  +  " "  +  data.Response.DataItems.VehicleRegistration.Model 

        **let**  toInsert  = { 
            vrm :  data.Response.DataItems.VehicleRegistration.Vrm , 
            year :  data.Response.DataItems.VehicleRegistration.YearOfManufacture , 
            make :  data.Response.DataItems.VehicleRegistration.Make , 
            model :  data.Response.DataItems.VehicleRegistration.Model , 
            engine :  data.Response.DataItems.SmmtDetails.NominalEngineCapacity  +  "  "  +  data.Response.DataItems.SmmtDetails.FuelType , 
            transmission :  data.Response.DataItems.VehicleRegistration.Transmission , 
            bodyStyle :  data.Response.DataItems.SmmtDetails.BodyStyle , 
            weight :  data.Response.DataItems.TechnicalDetails.Dimensions.UnladenWeight 
        } 

wixData . insert ( “VehicleDetails” , toInsert );

    }) 
    . **catch** (( err ) => { 
        $w ( '#VrmDetails' ). text  =  "Please enter the registration in the yellow box above." 
    }) 

}

Of course you can.
Just don’t submit the fetch results until the user answers the questions, then insert everything in one object (and don’t connect the submit button to your dataset.

Ok I’ve been trying to get my head around this on my own but just can’t figure it out without having 2 datasets 1 for the vehicle details and 1 for the questions and price given etc, the trouble I’m having is that the api has to run 1st and return the vehicle data I need, one of which is the weight which I need to give a price.

When the api returns the data if it didn’t store into a dataset immediately wouldn’t it be lost? and I take the weight which was stored in the dataset to give a price is there another way of going about this that I’m not getting?

It will be stored in the memory until you close the tab/refresh the page/navigate to another webpage.