Best answer

js code get input name

  • 9 November 2020
  • 3 replies
  • 333 views

Userlevel 2
Badge

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?

icon

Best answer by ikbelkirasan 19 November 2020, 18:39

View original

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

Userlevel 1

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

Userlevel 7
Badge +12

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.

 

Userlevel 7
Badge +11

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