Access the metafield, with getProductData

I’m trying to access the metafield called vsLastSync.
But can’t figure out the syntax. Please help.

The information is added with getProductData.
I try to get the metafield information with a forEach loop,
However a I can not output the individual value of the metafield.

product.vsLastSync.value gives me an error when running the workflow that states it “cannot read property ‘value’ of null”

product.vsLastSync gives me a an out put of

productData : 
{
  "value": "2024-09-28T16:41:45.837Z"
}

Which I can’t really access

Code:

input.getProductData.forEach((product) => {
    console.log('products title: ' , product.title);
    const productData = product.vsLastSync.value;
    console.log('productData : ' , productData);
  });

Input:

query{
   getProductData{
    title
    vsLastSync{
        value
      }
  }
}

Did you add that metafield to the workflow? Flow doesn’t know all of your shop-specific metafields and their types. You need to add them to the workflow, which allows you to access them like that above.

Instructions:

https://help.shopify.com/manual/shopify-flow/concepts/metafields

I have added in the get product data. Which seams to include all the product information.
My problem happens in the Run Code, where I only seem to get some information out of:

input.getProductData.forEach((product) => {
   const productData = product.vsLastSync
});

(vsLastSync is the name of the metafield)

But that is not getting the value of that metafield. Instead it gives me all the inputs I have defined.

If I write :

input.getProductData.forEach((product) => {
   const productData = product.vsLastSync.value
});

Then I get an error when running the workflow, staying that value can not be null.

Have you added the metafield to the workflow according to the docs I linked to?

For a simple metafield type you can access that via product.fieldName.value. But if it’s saying a value cannot be null, something in your code, likely fieldName is null. That suggests you either are missing the metafield in the workflow, the metafield doesn’t exist on the product you are running it again, or the value itself is null. “Value” may also refer to another field since it’s a generic term.

I looked made a consol.log and found that I had a two products with no value in there.
Which resulted in it not working. Added in some if statements. Its working now.
Thanks, this was driving me crazy.