How to request specific metafileds in Run Code node?

How to request specific metafileds in Run Code node?

kukin
Shopify Partner
3 0 3

What do I want to do:

I want to request from "run code" specific metafield by namespace and key, since it says "returns metafield by namespace and key" (see inputQuery.png). I assume this is also possible technically, since if I use "metafields" instead of "metafield" - I get all metafields surely in the output. But then the output size becomes very big and I alsways get ERROR: 50kb  OutputSizeExceeded.

 

inputQuery.png:

inputQuery.png

 

What do I do:

I do a request with the query from inputQuery.png, with `metafield` field.

What do I expect:

I expect to be able somehow to request a specific metafield by namespace and key.

What is actually happening:

If I use the input query from inputQuery.png - I get no metafields, I get output from output.png. If I try to provide namespace or key as argument - I get error from error.png.

 

output.png:

output.png

 

error.png:

error.png

 

Replies 5 (5)

Kalen_Jordan
Shopify Partner
800 38 144

Not seeing that metafield option in my autocomplete:

Screenshot 2024-07-08 at 7.55.54 PM.png

 

I'd probably just use metafields and then loop over them to find the namespace/key you're looking for?

paul_n
Shopify Staff
1501 162 351

I don't recommend looping over metafields as that pulls a lot of data. This is a gap in Run code that you cannot add metafield aliases via the input query. 

 

Add a "log ouput" step somewhere in the workflow and then choose that "metafield" via "Add a variable". It will say "requires arguments". Once it's added to the workflow you can use it in Run code via the aliases name

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
CapitalCastle
Shopify Partner
9 0 3

Hello paul_n-san

 

I would like to ask your answer of

> "Once it's added to the workflow you can use it in Run code via the aliases name".

I don't know how to get this alias name at Run code.

 

スクリーンショット 2024-08-19 13.48.39.png

 

スクリーンショット 2024-08-19 13.49.07.png

I appreciate that if you could advise it.

paul_n
Shopify Staff
1501 162 351

The input query is a way to pass the variables from the workflow into the Run code step's sandbox. You need to add that metafield's path to the input query like:

shop {
  yourMetatafieldAliasName {
    value
  }
}
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
CapitalCastle
Shopify Partner
9 0 3

Thank you paul_n-san!!

It was work fine!!