cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Scripting SAC with DropDown

Ganjos
Participant
631

Hi team,

I’m facing an issue while creating a form in SAP Analytics Cloud and I’d appreciate your help.

I have a table and a form.
When I select a row in the table and click a button, I retrieve the selected member and populate several input fields and a dropdown based on the member’s properties.

The InputFields are filled correctly, but the Dropdown isn't.
The value returned from the member property is not assigned to the dropdown, even though it is not empty.

In the final screenshot, I’ve added a visual explanation of the issue to make it clearer.

Snipped 1 – Populating the dropdown

Snipped 2 – Selecting a row in the table, clicking the button, and opening a popup that displays the data from the selected row

Here is the code I’m using:

 

Snipped 1:

Dropdown_31.removeAllItems(); // limpar o dropdown
 
var l_arr11= ArrayUtils.create(Type.string); // array de valores únicos
var allMembers5_$ = PlanningModel_1.getMembers("CP_DI_Projeto_PD", { limit: 1000 });
 
for (var a = 0; a < allMembers5_$.length; a++) {
    var tipo_projeto =allMembers5_$[a].properties["Tipo_Projeto"];
 
     var id20 = allMembers5_$[a].id;
    if (id20.startsWith("Dummy")) {
        continue;
    }
    // Verifica se o valor existe e ainda não foi adicionado
    if (tipo_projeto !== undefined && l_arr11.indexOf(tipo_projeto) === -1) {
console.log(tipo_projeto);
        l_arr11.push(tipo_projeto);
        Dropdown_31.addItem(tipo_projeto);
    }
}

Snipped 2:

 

var selections = Table_4.getSelections();
 
if (selections.length === 0) {
    return;
}
 
var sel = selections[0];
 
var selMeasure = sel[Alias.MeasureDimension];
 
if (selMeasure === undefined) {
 
    var dim = Table_4.getDimensionsOnRows()[0];
    var ds = Table_4.getDataSource();
 
    var member1 = ds.getResultMember(dim, sel);
console.log(member1);
 
    if (member1) {
        var descricao = member1.description;
        var tipoProjeto = member1.properties["CP_DI_Projeto_PD.Tipo_Projeto"];
var Datainicio = member1.properties["CP_DI_Projeto_PD.DataInicio"];
var DataFim = member1.properties["CP_DI_Projeto_PD.DataFim"];
 
        console.log(descricao);
        console.log(tipoProjeto);
 
 
        InputField_23.setValue(descricao);
InputField_25.setValue(Datainicio);
InputField_24.setValue(DataFim);
        Dropdown_29.setSelectedKey(tipoProjeto);
 
    }
}


Ganjos_1-1769012754315.png

 


Thank you,

Ganjos

Accepted Solutions (0)

Answers (1)

Answers (1)

CLTGravesen
Active Participant
0 Likes

Hello Ganjos,

I can't find any fault with the code, except one thing. 

In snippet 1: 

   Dropdown_31.addItem(tipo_projeto);

and in snippet 2, you have: 

 Dropdown_29.setSelectedKey(tipoProjeto);

I'm thinking you are doing everything right, but might have forgotten to change the ID of the dropdown.