Best answer

How to edit label of a dynamic field

  • 15 February 2021
  • 2 replies
  • 29 views

Userlevel 1

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

icon

Best answer by ikbelkirasan 15 February 2021, 12:13

@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

2 replies

Userlevel 7
Badge +11

@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;
});

 

Userlevel 1

It works ! Thank you very much @ikbelkirasan !

Reply