How Can I Fetch Only the 5th Line from a Query to Match the Company String?

This topic was automatically generated from Slack. You can find the original thread here.

Hello how can i fetch only the 5th line from this query. i want to match the company with the company string which is the 5th line form the text field

Hi, please refer to this video about how to hover over individual step exports to find the Copy Path link so you can copy references to data across other steps:

The video shows how to use webhook data, but the same principle applies to the entire product

well you see my case is a different, so the text field have many rows and they are not selectable as paths

im trying to fetch or filter lets say 5th row from the text field that have only 1 selectable path

Got it. Then you will need to reach for code to help you with that.

can you please write a Node.js code step that will extract strings formatted like the below to extract an object instead?

**first name** Dylan
**last name** Pierce
**company** Pipedream

Sure, here’s a Node.js code step that extracts the information from the given string and returns it as an object: export default defineComponent({ async run({ steps, $ }) { const input = `**first name** Dylan **last name** Pierce **company** Pipedream`; const lines = input.split("\n"); const result = {}; lines.forEach((line) => { const [key, value] = line.split("** ").map((item) => item.replace("**", "").trim()); result[key] = value; }); return result; }, }); This code will return an object with the extracted information: ```
on { “first name”: “Dylan”, “last name”: “Pierce”, “company”: “Pipedream” }

can you please write a Node.js code step that will extract strings formatted like the below to extract an object instead?

**first name**: Dylan
**last name**: Pierce
**company**: Pipedream

that’s very close, but could you convert the input variable into a string prop instead?

Sure, here’s a Node.js code step that extracts the information from the given string and returns it as an object: export default defineComponent({ async run({ steps, $ }) { const input = `**first name**: Dylan **last name**: Pierce **company**: Pipedream`; const lines = input.split("\n"); const result = {}; lines.forEach((line) => { const [key, value] = line.split(": ").map((item) => item.replace("*", "").trim()); result[key] = value; }); return result; }, }); This code will return an object with the extracted information: ```
on { “first name”: “Dylan”, “last name”: “Pierce”, “company”: “Pipedream” }

Sure, here’s the updated Node.js code step with the input variable converted into a string prop: ```
export default defineComponent({ props: { input: { type: “string”, label: “Input Text”, }, }, async run({ steps, $ }) { const lines = this.input.split(“\n”); const result = {}; lines.forEach((line) => { const [key, value] = line.split(“: “).map((item) => item.replace(””, “”).trim()); result[key] = value; }); return result; }, });

That one is worth a shot for your use case. It might not be perfect, but I think it will get you there.

you are awesome mate have a great day :slightly_smiling_face:

Thanks you too! Just trying to help :slightly_smiling_face:

its now working alright but when i try to use this path when i try to create a lead its not letting me and throwing this wrror

image.png

this is my path

image.png

node3 code

The statements with the handlebars {{ }} in prop fields are evaluated using Javascript.

You’ll need to write valid Javascript in order for the variable to be referenced correctly.

If you’re not familiar with Javascript, I recommend getting started with a resource like Eloquent Javascript. It’s a great introduction to learning it.

Additionally, you can ask @Pi questions to help debug your Javascript code.

steps.node_3.$return_value[] is not a valid Javascript statement, I recommend copying the path to the new export variable you’d like to reference and paste it again into the prop’s input field

what should be the return result code to be used as a string ?