Hello everyone, I’m trying to parse and save text data stored in Customer Notes, into several Metafields. For now I chose single line Metafields, Flow run history shows no error but unfortunately nothing happens.
The code you provided looks mostly correct for parsing and extracting the “City” information from the customer notes. However, it seems that you are not actually saving the extracted data into the Metafields.
To save the extracted data into the Metafields, you need to use the Shopify API or Shopify SDK to update the customer’s Metafields. Here’s an example of how you can modify your code to save the extracted “City” data into a Metafield:
{%- assign customernote_lines = customer.note | split: "
" -%}
{%- assign datacity = '' -%}
{%- for line in customernote_lines -%}
{%- if line contains "City:" -%}
{%- assign datacity = line | replace: "City:", "" | strip -%}
{%- endif -%}
{%- endfor -%}
{% comment %}
Assuming you have already set up the necessary Metafields for the customer, you can save the extracted city data like this:
{% endcomment %}
{%- assign namespace = 'your_namespace' -%}
{%- assign key = 'city' -%}
{%- assign value = datacity -%}
{% comment %}
Replace `customer.id` with the actual customer ID you are working with.
{% endcomment %}
{% shopify_api 'PUT', "/admin/api/2021-07/customers/{{ customer.id }}/metafields.json" %}
{
"metafield": {
"namespace": "{{ namespace }}",
"key": "{{ key }}",
"value": "{{ value }}",
"value_type": "string"
}
}
{% endshopify_api %}
In the above code, replace ‘your_namespace’ with the namespace you’ve set up for your Metafields, and ‘city’ with the key for the specific Metafield you want to store the city data in.
Make sure you have the necessary permissions to update Metafields using the Shopify API, and ensure that you are running this code in an appropriate context (such as a Shopify app or a custom Shopify script).
If I managed to help you then, don’t forget to Like it and Mark it as Solution!
Thanks for the answer and time @Moeed , issue is question is about Shopify Flow App in this forum. Simply because in Shopify Flow App:
Customer Id aka {{ customer.id }} is already filled when you reach step 4, so it shouldn’t need to repeat neither calling API (again). Shopify Flow uses GraphQL mutations to query API.
So I think the key problem where is that you are trying to update the note and then used the updated note in the next step. Flow pre-fetches all data used in a workflow at the start, in order to optimize API use. So it will use the old note in that metafield action. It you want to refetch that note, then you can add a short wait step before the metafield action. Anything after the wait step will be fetched after the wait step completes.
Thanks for feedback, my bad some code was wrong so input data was empty.
Finally got it working removing step 3 to go directly to 4 and updating code a bit. Using a short wait step was a good suggestion, but not needed. Also make sure to click “Show all” Metafields in admin because when created by Flow, by default they’re unpinned and lack definition - so they’re hidden in UI.
Did you find the way to put into customer metafield whats in customers note?
Trying to put into customer metafield whats im getting from customer note lik “11111” text line string.
If you mean put the note an an order into a metafield, wouldn’t you simply add {{ order.note }} to the value field and use the namespace/key of the metafield you want to store it in.
I wanna add a custom field to registration form. as I understood I have to save it as a note. but I could not find how I can pass this note to the custom field. I wanna also show this field in customer page. can you please help me ?
for custom fields I cannot define value. there is no value field.
What does “doesn’t work” mean? Show the problem you are having.
I do see you are setting a single line string but you have newlines in your code. Try adding hyphens to that last variable to remove whitespace, like {{- city -}}
Thanks for your answer.
Regarding flow application, I have added a custom fields as a file. so users can upload a file. but in note I can see jut the name of the file. so when I update the custom fields, it just send the name of that. I cannot have the path of the file to download. can you please help me with that?
I think notes are plain text. It’s unclear what you are using to add the name there. But there is a URL field on metafields that have a file refererence.