Hold for editions feedback and questions

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.

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?

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.

1 Like

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-rest-graphql/m-p/1338407) 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.

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 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):

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?

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.

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.

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

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.

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

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

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.

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

1 Like

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.

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.

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

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

The video says it all. Thanks

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!

1 Like