Code for using datahook to insert image from another field or database using filter

Seems that you could use a “if cell is not empty” or other filter you could then set up the hook to then pull in image from another field or field from a separate database.

Anyone have anything along this lines?

You can query a database and find items that have a certain field empty using the isEmpty() query option, then you can update that field using the update() method.

Example code (inside hook):

import wixData from 'wix-data';

wixData.query("myCollection")
  .isEmpty("bio")                    //Get the empty fields in the collection
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let items = results.items;
      items.forEach((item) => {      //For each item with "bio as empty"
        let toUpdate= item;
        
        toUpdate['picture'] =         //Put picture here 
        
        wixData.update("myCollection", toUpdate) //Updates that item, you can use insert into new database
          .then( (results) => {
              let item = results; //see item below
          } ).catch( (err) => {
              let errorMsg = err;
          } );
      })
      
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );