Skip to main content
Solved

Get the "name" property from a BPA enumeration

  • March 11, 2024
  • 2 replies
  • 112 views

Forum|alt.badge.img+13
  • Hero (Partner)
  • 161 replies

Hello everyone,
I'm trying to retrieve the "Name" property of my BPA enumeration: 

Indeed, I can retrieve the ID using "execution.getVariable('') but what I'm interested in is the "Name" property.

Do you have any ideas?
Thanks in advance

Best answer by Buddhi Gunasekara

Only the id of the selected user task enumeration is readily available in the execution. Your easiest option is to introduce a duplicate json to execution that holds the enum in user form.

 Script task 1:

var json = '{"enum1":[{"id": "DB_TEST1", "name": "Test1"}, {"id": "DB_TEST2", "name": "Test2"}]}';
execution.setVariable('json', JSON.parse(json));

Script task 2:

var jsonObj = execution.getVariable("json");
var sl = String(selectById(jsonObj, execution.getVariable('enum1')));
execution.setVariable('selected', sl);

function selectById(json, id) {
for (var i = 0; i < json.enum1.length; i++) {
if (json.enum1[i].id == id) {
return String(json.enum1[i].name);
}
}
}

 

Be sure to place script task 1 after the last user task.

 

Another option is to add the enum name resolution by id logic as a projection function and call it via an API task where necessary.

2 replies

Forum|alt.badge.img+7
  • Hero (Employee)
  • 67 replies
  • Answer
  • March 12, 2024

Only the id of the selected user task enumeration is readily available in the execution. Your easiest option is to introduce a duplicate json to execution that holds the enum in user form.

 Script task 1:

var json = '{"enum1":[{"id": "DB_TEST1", "name": "Test1"}, {"id": "DB_TEST2", "name": "Test2"}]}';
execution.setVariable('json', JSON.parse(json));

Script task 2:

var jsonObj = execution.getVariable("json");
var sl = String(selectById(jsonObj, execution.getVariable('enum1')));
execution.setVariable('selected', sl);

function selectById(json, id) {
for (var i = 0; i < json.enum1.length; i++) {
if (json.enum1[i].id == id) {
return String(json.enum1[i].name);
}
}
}

 

Be sure to place script task 1 after the last user task.

 

Another option is to add the enum name resolution by id logic as a projection function and call it via an API task where necessary.


Forum|alt.badge.img+13
  • Author
  • Hero (Partner)
  • 161 replies
  • March 12, 2024

Hi @Buddhi Gunasekara,

This solution works perfectly!
I hadn't thought of it at all.
Thank you very much.