Skip to main content
Best answer

js code get input name

  • November 9, 2020
  • 3 replies
  • 377 views

Forum|alt.badge.img

Hi, for a project that i'm working on i need to have the names of the vars for my custom code with code by zapier

What i want to have is besides the values 322,133,call,bellen I also want ID,STATUS, last activity type,last activity subject as vars in my js?

 

is there anyway how I can get that data?

Best answer by ikbelkirasanBest answer by ikbelkirasan

Hi @Jeff Thorns - Instead of passing all the values in the same field called data, try creating a separate field for each variable. This way, you’ll have access to each variable by its name via the inputData object. for example, if you add a new field called ID, you will be able to access it using inputData.ID.

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

|ʙill ⨍elix|

Assuming that somewhere in your workflow the Data is parsed into an Object, then Object.keys() should work: 
 

const data = {
  ID: 322,
  Status: 133,
  Last Activity Type: 'call',
  Last Activity Subject: 'Bellen'
};

console.log(Object.keys(data));
// expected output: Array ["ID", "Status", "Last Activity Type", "Last Activity Subject"]

output = [{vars: Object.keys(data)}]


reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • November 19, 2020

Hi @Jeff Thorns - Instead of passing all the values in the same field called data, try creating a separate field for each variable. This way, you’ll have access to each variable by its name via the inputData object. for example, if you add a new field called ID, you will be able to access it using inputData.ID.

 


nicksimard
Forum|alt.badge.img+11
  • Zapier Staff
  • 2115 replies
  • February 5, 2021

Hi @Jeff Thorns!

I wanted to check in with you on this one, since we didn't hear back after our last message. Did you still need help here or were you able to resolve things? Please let us know :)