Solved

Get the "name" property from a BPA enumeration

  • 11 March 2024
  • 2 replies
  • 50 views

Userlevel 5
Badge +11

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

icon

Best answer by Buddhi Gunasekara 12 March 2024, 06:53

View original

2 replies

Userlevel 3
Badge +5

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.

Userlevel 5
Badge +11

Hi @Buddhi Gunasekara,

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

Reply