Hold for editions feedback and questions

paul_n
Shopify Staff
916 127 221

As part of Winter Editions `24, Flow launched a new Run code action. If you have questions, comments, etc this is the place to ask. 

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.
Replies 30 (30)

JesperUnna
Excursionist
15 0 9

Hi Shopify,

The new Run code feature sounds promising! Many of our wholesale customers request a CSV line_sheet (overview of products, barcodes, image links etc) for their orders. But it is currently not easily done through Shopify. My background is in javascript, so being able to execute javascript in a flow, could make sense for generating the desired super simple CSV-file... But would you say, it a possible usecase for the feature?

paul_n
Shopify Staff
916 127 221

General the comma-separate variables part should be easy. That said, Flow doesn't currently generate files or have a way to do file handing. So you might need to rely on something else to do the attachment part. 

 

It's possibly you could use Google Sheets for that - Flow does have a connector for Sheets. 

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.

xdoomx
Visitor
2 0 0

Is this the right place to set up a Flow to delete a line item from an order?

I've got this code sample that works in GraphQL (from https://community.shopify.com/c/customers-discounts-and-orders/remove-lineitem-form-order-via-api-re...) but totally lost on how to convert this for RUN CODE.

mutation orderEditBegin($id: ID!) {
  orderEditBegin(id: $id) {
    userErrors {
      field
      message
    }
    calculatedOrder {
     	id
      lineItems(first: 5){
        edges{
          node{
            id
            quantity
          }
        }
      }
      originalOrder{
        lineItems(first:5){
          edges{
            node{
              id
            }
          }
        }
      }
      
    }
  }
}



mutation changeLineItemQuantity {
  orderEditSetQuantity(id: "gid://shopify/CalculatedOrder/55116136575", lineItemId: "gid://shopify/CalculatedLineItem/13953156284543", quantity: 0) {
    calculatedOrder {
      id
      addedLineItems(first: 5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

mutation commitEdit {
  orderEditCommit(id: "gid://shopify/CalculatedOrder/55116136575", notifyCustomer: false, staffNote: "I edited the order! It was me!") {
    order {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

Do I need to do 3 separate RUN CODE blocks to complete the line item delete? Any guidance or even a complete solution would be appreciated.

I've had a look at https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples for other hints as well.

paul_n
Shopify Staff
916 127 221

See input data section here, and the list of limitations. The action is not yet ready for API queries. The "input" is for querying Flow's environment, not the API.

https://help.shopify.com/en/manual/shopify-flow/reference/actions/run-code

 

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.

brodrig
Shopify Partner
13 1 2

@paul_n I'm looking for functionality in Flows that can help me add an order tag using a value from the orders custom attributes. I haven't been able to do this earlier in Flow and am wondering if this new feature could help me achieve this. Included a screenshot below of what I think the function would look like (TODO is the actual tagging of the order):

Screenshot 2024-02-14 at 3.48.53 PM.png

My understanding is that this would not be possible because we don't have access to the API from here. Can you confirm this? And are you aware of any other functionality in Flows that would help me achieve this?

 

brodrig
Shopify Partner
13 1 2

P.S. The overall goal is to be able to add different order tags from the website frontend depending on the customers behavior. I wasn't able to find a way to add tags directly, so I resorted to adding custom attributes through the /cart endpoints. I figured Flows would help me find an automated way of translating these custom attributes into an order tag.

paul_n
Shopify Staff
916 127 221

You don't need API access in Run code to solve this use case. You can feed in customAttributes from the Flow environment (which does the API access for you) as you are doing in the input query (remove the commas by the way). 

 

You can't call the tags API from the action, but you can pass the tag(s) you want to add through the return data. And then put that as a variable inside the Add tag action.

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.
Verdant-Spark
Shopify Partner
99 8 32

Hi Paul - interestingly this is just the use case which we're trying, but the add tag action doesn't seem to persist the input variable, and the tag added to the order is an empty array [] - however, if I use the same variable as the input to the 'add note' action then the text is correctly stored, so looks like there's a bug in the add tag action.

paul_n
Shopify Staff
916 127 221

After you put in the liquid you need to hit enter to save it. It will look like a tag. I recommend also saving the liquid in the description in case you later need to modify it. 

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.
Verdant-Spark
Shopify Partner
99 8 32

Thanks for that - that worked (not the most intuitive UI), and the functionality opens a good set of opportunities. I like.

paul_n
Shopify Staff
916 127 221

Agree, in the future you could use a separate step to set the liquid variable and then just enter a basic variable in that tag field

 

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.
Verdant-Spark
Shopify Partner
99 8 32

TBH, I think it's easier than that - all it needs is an 'add tag' button next to the entry field so that there's a positive action!

Alicia_P
Tourist
9 3 3

It would be really handy to be able to do this type of query in the run code action:

query{
    metaobjects( type: "all_group_tags" first: 250){
        nodes{
           displayName
        }
    }
}



I have a "uniqe" code I tag customers with to be able to group them and save the used tags in a metaobject to be able to get the name of the group in a easy way. When a customer is created I generate a random group code, but since it isn't totally uniqe I need to check so it doesn't exist first (if the customer is the first to register to that group). As I understand there is currently no way of getting a metaobject information (in flow) unless it has the ownerType shop (stored in the shop's metafield, but I can't do that through the admin dashboard unfortunately). And the metaobjects created in the admin dashboard doesn't have that (unfortunately).
Maybe there there is another way of doing this?
/Kind regards Alicia

paul_n
Shopify Staff
916 127 221

Hi, to clarify the input query in the Run code action is to query the data available in Flow's environment. It is not to get more data.

 

We have a separate project underway to make accessing Metaobjects in Flow much easier. We will likely have an action to get a Metaobject value and return it into the Flow. That could then be passed to Run code if needed.

 

Regarding accessing Metaobjects in Flow, you can access a metaobject as long as it's tied to a resource (shop, customer, product, etc). It's a bit hard to use but it's possible. The project I mentioned is also looking to clean up that approach.

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.

Leffrey
Explorer
40 0 17

Did they finally introduce a way to insert steps, move steps and copy steps?  

paul_n
Shopify Staff
916 127 221

You can already insert and move steps, unless you mean something more specific. Copy is missing. 

 

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.
Leffrey
Explorer
40 0 17

Can you tell me how to move a step or insert a step.  Just to clarify....

1. Insert a new step between 2 other steps.  

2. Move a step from between 2 current steps to another area in the same flow.

paul_n
Shopify Staff
916 127 221

To insert a new step:

  1. Hover on the line and click delete
  2. Put in new step
  3. Drag from the blue circle on the previous step to the blue circle on the new step and release.
  4. Do the same to connect the new step to the subsequent step. 

The process is roughly the same for moving a step. 

 

Here's a video: https://screenshot.click/14-04-6u9i6-1zotw.mp4

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.
Leffrey
Explorer
40 0 17

The video says it all.  Thanks

 

 

JDavis1
Tourist
5 0 0

Hello,

 

It seems like this tool doesn't yet support TextEncoder or crypto.subtle (though perhaps I'm just doing something wrong!)

 

I'm trying to hash some data as sha256 before I send it via API, but neither the Liquid Filter or 'Run Code' functions seem to enable this workflow (the Liquid Filter should be working, but it's giving an 'undefined filter' error).

 

I believe both TextEncoder and crypto have wide support, so I'm hoping they're on the roadmap for 'Run Code' 🤞

 

Here's an snippet of what I'm trying to run:

function sha256(message) {
  // encode as UTF-8
  const msgBuffer = new TextEncoder().encode(message);

  // hash the message
  const hashBuffer = crypto.subtle.digest("SHA-256", msgBuffer);

  // convert ArrayBuffer to Array
  const hashArray = Array.from(new Uint8Array(hashBuffer));

  // convert bytes to hex string
  const hashHex = hashArray
    .map((b) => b.toString(16).padStart(2, "0"))
    .join("");
  return hashHex;
}

and the errors in Flow 'Run Code':

 

JDavis1_0-1711565780876.png

JDavis1_1-1711565791843.png

 

Thanks!

Jack

paul_n
Shopify Staff
916 127 221

Correct those libraries are not supported. Can you elaborate on your use case for them? What API requires SHA256?

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.
JDavis1
Tourist
5 0 0

Thanks for getting back to me! 

 

For privacy / security; the Pinterest API, Meta API and Google Ads API all require SHA256 hashing of anything sensitive. (Pinterest Example, Google Example, Meta Example). I'm sure other platforms do too, but those are 3 that I've come across already.

paul_n
Shopify Staff
916 127 221
Thanks for the info. You cannot yet call those APIs via the Run code action
but we have plans to enable "fetch" and also plan to address any library
short-comings at the same time.
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.
JDavis1
Tourist
5 0 0

I've been calling the APIs using the 'Send HTTPS Request' step in the flow. My goal was to format and hash the data in Run Code before passing it onto the next step in the flow. I also tried to use the SHA256 Liquid Filter directly within the 'Send HTTPS Request' step, but it isn't currently supported.

Mussty
Excursionist
34 3 7

Hi, I'm trying to use the run code feature where I want to make a calculation and output it as kgQuantity. I want to then use this value later in the flow. It seems I can only recall the {{runCode.""}} on the immediate step after but not further down the line? I have a small glitch in our POS system which sets 500g product inventory to zero I'm trying to capture it before its set to 0 then to update it back once it does. I normally send the payload in an http to Make.com and was hoping I can use the Run Code feature to solve this.

 

Mussty_0-1712771682450.png

 

I'm getting the following error:

 

Mussty_1-1712771982400.png

 

 

paul_n
Shopify Staff
916 127 221

Hi, looks like we didn't document that limitation. If there is a wait step, the output will not be available on the other side. I don't have an ETA on this, but will report back when I know more. 

Docs:

https://help.shopify.com/en/manual/shopify-flow/reference/actions/run-code#limitations

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.
paul_n
Shopify Staff
916 127 221

This is a limitation of wait steps. When you have data coming from another source and then potentially waiting for up to 90 days, the data can get stale. So currently, it's not stored. Are you able to refactor to put the wait step in a different spot? 

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.
Mussty
Excursionist
34 3 7

Hi @paul_n , right I see. Unfortunately no, there is a bit of a delay, so I have to wait. Usually within the first 30seconds the inventory goes to zero, If I try to run code then it would calculate it from the new quantity. I just realised, I should be able to replace it with {{inventoryQuantityPrior}}.  However, I can see many scenarios where the wait step would be useful and the output could be used. Maybe limit it to 24 hours so the data doesnt get stale? I'm interested in the data value at the time it is run, so it wouldn't matter to you if it's stale or not, I might have a particular need for it. :))

AttaC
Visitor
1 0 0

I'm looking for a way to tag, say, top 10 most purchased products in the past week. I could pass in getOrderData, then count and sort within the Run Code block. However, I wasn't able to output the product objects themselves (see screenshot).

AttaC_0-1712806023690.png

My workaround was to turn the list of product IDs into a query string ((id: XXX) OR (id: YYY) OR ...), then use that string in a subsequent Get Product Data block, but then the result would come in a different ordering.

 

Is there any way I can achieve this with Run Code's current implementation? If not, is there anything in future plans about returning GraphQL objects themselves, in a way that can be looped over in later Flow blocks?

paul_n
Shopify Staff
916 127 221

The Output types are unaware of Shopify resources. Generally, I would output only what you need for subsequent steps. Outputting a list of product objects is counter-productive because you'll then need to write liquid in the next step to get the IDs you want. 

 

If you want to get Shopify resources into a code step right now, the best way is to use a step before the Run code action to get the data that you want. Then you can access the information in Run code.

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.