Skip to main content
Best answer

How to edit label of a dynamic field

  • February 15, 2021
  • 2 replies
  • 201 views

Hello, I’m building an integration and I have in an action a dynamic dropdown followed by another dropdown which values depends on the first one. 
In order to do the second dropdown, I used a dynamic field which returns the following : 

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;
    const field = { key : 'champ_type', choices: results.items.map(x => x['fieldId']) }
    return field;

My problem is that I get a list of fieldId and I would like those items to have an understandable label ( in  my case, it’s fieldLabel instead of fieldId). Can someone help me with this ? 

 

Thank you. :) 

Best answer by ikbelkirasanBest answer by ikbelkirasan

@sub150 - Try the following code snippet:

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = response.json;

  const choices = results.items.reduce((prev, current) => {
    prev[current.fieldId] = current.fieldLabel;
    return prev;
  }, {});

  const field = {
    key: "champ_type",
    choices,
  };
  return field;
});

 

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.

2 replies

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • February 15, 2021

@sub150 - Try the following code snippet:

return z.request(options).then((response) => {
  response.throwForStatus();
  const results = response.json;

  const choices = results.items.reduce((prev, current) => {
    prev[current.fieldId] = current.fieldLabel;
    return prev;
  }, {});

  const field = {
    key: "champ_type",
    choices,
  };
  return field;
});

 


  • Author
  • Beginner
  • 3 replies
  • February 15, 2021

It works ! Thank you very much @ikbelkirasan !