cancel
Showing results for 
Search instead for 
Did you mean: 

javascript to transmit value to dynamic field in SAP Screen Personas 3.0 Service Pack 2

maximilian_fischer
Discoverer
0 Kudos

Hi! I've created a flavor with SAP Screen Personas 3.0 Service Pack 2 for the transaction CV4N. Now I've created a drop-down list which transmits a value to the "descriptor" in the classification (tab classification in CV4N). My problem is, if the order of the characteristics is changed, the value from the drop-down list must be transmitted to the correct characteristic "descriptor" in the classification. Can it be possible? Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

clemens_gantert
Active Participant
0 Kudos

Hello,

the classification tab in CV04N is dynamically created depending on what classes are used for the current document (or its a GuiTableControl and the below applies to it as well).

Since the screen is dynamically created, the usual approach of accessing a control by its static ID fails (because there is no static ID).

I am going to outline an approach you can use to find the field you are looking for.

The control IDs in dynamic screens typically follow a pattern with a running index, like "CONSTANT[0]", "CONSTANT[1]". The classification screen has a label column and a value column. Let's assume the constant part of the label column is "LABELID" and the constant part of the value column "VALUEID". Use the property inspector to determine correct constant parts.

So you have to write a script that loops through the list and compares the label text with the expected text to determine the index of the field you are looking for.

For example:

var index = 0;

while (session.idExists("LABELID["+index+"]"))

{

     if ( session.findById("LABELID["+index+"]").text ==="label I am looking for")

     {

          var valueID = "VALUEID["+index+"]";

          break;

     }

     index++; 

}

// do something with the value id, like: session.findById(valueID).text = value;

Of course you have to take into account the possible label translations if applicable.

Best Regards,

Clemens Gantert

maximilian_fischer
Discoverer
0 Kudos

Clemens Gantert wrote:

Hello,

the classification tab in CV04N is dynamically created depending on what classes are used for the current document (or its a GuiTableControl and the below applies to it as well).

Since the screen is dynamically created, the usual approach of accessing a control by its static ID fails (because there is no static ID).

I am going to outline an approach you can use to find the field you are looking for.

The control IDs in dynamic screens typically follow a pattern with a running index, like "CONSTANT[0]", "CONSTANT[1]". The classification screen has a label column and a value column. Let's assume the constant part of the label column is "LABELID" and the constant part of the value column "VALUEID". Use the property inspector to determine correct constant parts.

So you have to write a script that loops through the list and compares the label text with the expected text to determine the index of the field you are looking for.

For example:

var index = 0;

while (session.idExists("LABELID["+index+"]"))

{

     if ( session.findById("LABELID["+index+"]").text ==="label I am looking for")

     {

          var valueID = "VALUEID["+index+"]";

          break;

     }

     index++;

}

// do something with the value id, like: session.findById(valueID).text = value;

Of course you have to take into account the possible label translations if applicable.

Best Regards,

Clemens Gantert

Hello,

I have a question regarding the dynamic assignment of characteristics.

Can I store/find a unique LableID for a characteristic?

Currently, this depends on the language( session.findById("LABELID["+index+"]").text ==="label I am looking for"), but users log on in different languages.

When the system language is German/French, but the keyword in JavaScript is stored in English, this value will not be found.

Thanks in advance.

Best regards

Maximilian Fischer

clemens_gantert
Active Participant
0 Kudos

Hi,

on a normal, non-generated screen, the label - or all fields for that matter - would have fixed, static IDs. Unfortunately, this does not hold true for generated screens or the cells in a table.

Maybe, there is a away to determine the index of the label you're looking for by some RFC (maybe even custom RFC), but in my opinion the outlined approach is the more practical one.

On a side note you can determine the current user's logon language through the scripting property "session.info.language".

So you can write your test in the following manner:

var labelMap = {

          "EN": "label in English",

          "DE": "label in German",

          "FR": "label in French"

// add more languages as needed

};

var labelText = labelMap[session.info.language];

...

if ( session.findById("LABELID["+index+"]").text === labelText ){


}

Best Regards,

Clemens Gantert

Answers (0)