Skip to Content
0

Problems with script, trying to add value in a text field

Mar 27, 2017 at 01:00 AM

159

avatar image

Hello everyone,

I'm a newcomer with this tool. I'm trying to add some fields in vatious text components but always returns error.

In this field:

I want to put the following field from my query:

This is the highest value in this table. Always will be represented in that position, but can vary the plant.

I tried wit this but doesn't work.

TEXT_50.setText("Valores" + EXACTITUD_RM.getData("007WRP6DPY9YEPFINT6WIXIB2", {}).scalingFactor);

Someone can give a hand?

Regards

1.png (3.1 kB)
2.png (6.0 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Juan Elías Rivero Domínguez Mar 30, 2017 at 02:05 PM
1

Hello to everyone. Sorry for my late response. The conditions changed and I did it everything from 0. The view was modified to show all the plants, from there after sort and rank the values I applied the conditions for the 2 top and 2 botton values. The code used was this:

    var val = 0.0;
    var rank_n = 0.0;
    
    var Dim_For_Top = EXACTITUD_RM.getMembers("0PLANT", 1000);
    Dim_For_Top.forEach(function(element, index) {
    val = EXACTITUD_RM.getData("007WRP6DPY9YEPFINT6WIXIB2",{"0PLANT":element.internalKey}).value;
    rank_n = EXACTITUD_RM.getData("007WRP6DPY9YEPFFXUER7PC4L_Formula1",{"0PLANT":element.internalKey}).value;

    if (rank_n == 1 )
    {
         TEXT_50.setText(Convert.floatToString(val));           
        }
     else if (rank_n == 2)
    {
         TEXT_52.setText(Convert.floatToString(val));
    }
    
    else if (rank_n == Dim_For_Top.length-1)
    {
         TEXT_54.setText(Convert.floatToString(val));
    }
    
     else if (rank_n == Dim_For_Top.length)
    {
         TEXT_63.setText(Convert.floatToString(val));  
    }
    
});

And the result was:

a=9.83 ͌ 9.8 first value b=9.79 ͌ 9.8 second value

c=8.65 ͌ 8.7 third value d=8.30 ͌ 8.4 fourth value

For the present data:

Thank you very much for the help Poovarasan, Agata and Koen.

Regards.


daga.png (13.6 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Top stuff Juan. Very clever solution :-)

0
Poovarasan Boopalan Mar 28, 2017 at 05:55 AM
-1

Hi Juan,

Do you want to have result in as average in your output?

If not you can change the result calculation as maximum in initial view of datasource.

Then you can bind the value to text so will always get maximum value on the text box.

Select maximum and use text binding as below to get the maximum value in text box.

In the highlighted property select the result cell.

Thanks,

Poovarasan


Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi, thanks for your answer. The bex query is configured to show the values in order. I only wanna show its in the text box separately.

Regards.

0
Agata L. Mar 27, 2017 at 10:03 AM
0

Juan,

If you always want to bring in the highest value then the code would look something like this:

/*select all members of your Plant dimension*/

var myArray = DS_1.getMembers("0PLANT", 100);

var myPlant = "";

var myValue = 0.00;

/*loop through the array of your Plants and retrieve the highest value*/

myArray.forEach(function(element, index) {

myPlant = element.internalKey;

if (myValue < DS_1.getData("00O2TFZLON3KAMGYC50MHY68G", {"0PLANT":myPlant}).value) {

myValue = DS_1.getData("00O2TFZLON3KAMGYC50MHY68G", {"0PLANT":myPlant}).value;

}

else {myValue = myValue;}

});

/*update your text component*/

TEXT_50.setText("Valores: " + Convert.floatToString(myValue,"#,##0"));

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Agata,

Thanks for your answer and your help.

Well, i did it some minimum changes in your code, but is giving an error:

Could not find member "G102"(G108/G109/G112) of dimension "0PLANT" in getData ("007WRP6DPY9YEPFINT6WIXIB2", {"0PLANT": "G102"}). It may have been discarded by a filter.

/*select all members of your Plant dimension*/

var myArray = EXACTITUD_RM.getMembers("0PLANT", 4);

var myPlant = "";

var myValue = 0.00;

/*loop through the array of your Plants and retrieve the highest value*/

myArray.forEach(function(element, index) {

myPlant = element.internalKey;

if (myValue < EXACTITUD_RM.getData("007WRP6DPY9YEPFINT6WIXIB2", {"0PLANT":myPlant}).value) {

myValue = EXACTITUD_RM.getData("007WRP6DPY9YEPFINT6WIXIB2", {"0PLANT":myPlant}).value;

}

else {myValue = myValue;}

});

/*update your text component*/

TEXT_52.setText("Valores: " + Convert.floatToString(myValue,"#,##0"));

Also the user now is asking to add the values in the following form:

Table:

Dashboard:

Some suggestion?

Regards.

11.png (8.0 kB)
22.png (5.9 kB)
0
Agata L. Mar 28, 2017 at 09:47 AM
0

Juan,

1. Please can you ensure the following settings are set up in the Initial View of your data source, on 0PLANT:

and

both need to be Only Values with Posted Data. Then, hopefully, the error that you are getting, not able to find member "G102" should disappear. For clarity, would you please switch on the keys on your 0PLANT, so that we can see what the keys are, if G102 is indeed the one that's filtered out and thus giving an error?

I have been having problems using getMembers() function, as in my Design Studio it often retrieves master data (or some random data) instead of query set - it is possible that you may be having the same issue. But, first, please set both filters to display Only Values with Posted Data to see if this will fix the problem.

2. Now, can you please clarify if your data source always has 4 members, or any number of members? And if you want exactly 4 text components, displaying values from highest to lowest? If so, that might be a bit difficult to do, as getMembers() function retrieves the members in no particular order and I would have to find out if there is a way of creating another array of getData() results while looping through individual memebrs and sorting it. I haven't tried that before. (By the way, it seems like you are trying to create Tiles to display your data, something I have also tried in the past, and let me tell you it's a lot of effort :D Word of advice - this is the perfect time to change your design or you will end up with working with the arrays forever, and this will slow down the performance of your dashboard dramatically...)

3. Lastly, if you get the "G102" issue sorted, and you are happy with the code I have provided for the highest value, then you can optimise it better, like this:

/* You can move your variables to Global variables, so you don't have to define them here */

var myArray = DS_1.getMembers("0PLANT", 100);

var myPlant = "";

var myValue = 0.00;

/* new variable I am introducing */

var CurrentPlant = 0.00;

/*loop through the array of your Plants and retrieve the highest value*/

myArray.forEach(function(element, index) {

myPlant = element.internalKey;

/* read the current Plant value once and then only reference it, this will only get the data once instead of two times - better for performance */

CurrentPlant = DS_1.getData("00O2TFZLON3KAMGYC50MHY68G", {"0PLANT":myPlant}).value);

if (myValue < CurrentPlant {

myValue = CurrentPlant;

}

else {/* don't do anything */}

});

/*update your text component*/

TEXT_50.setText("Valores: " + Convert.floatToString(myValue,"#,##0"));

4. I like Poovarasan's answer above. But it does create a specific view of your query and if you want to use your query later for something else (like the 4 text components), then you will need to create another query or data source or insert another copy of the key figure without the max on it. If your use of array would be just a one off, I would use my code.


o45xn.png (14.0 kB)
7o89l.png (13.0 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Agata. Thanks again for your answer. In reference to your suggestions:

1.- I have selected the option Only Values with Posted Data

2.- My datasource is configured to show always only 4 members and yes, I want exactly 4 text components, displaying values from highest to lowest. Can you give some advice to see the factibility?

3.- I didn't try this option because show the error again.

I will try also with something that i have in mind.

Regards.

111.png (8.1 kB)
222.png (8.7 kB)
0

Juan,

1. Is it still showing you the same error? Can you please display your 0PLANT keys and show a screen shot? I think your getMembers() might still be retrieving master data instead of query set. Which version of Design Studio are you on? Also, is there another key figure in you data source, except for Exactitud RM? If there is, and you are only hiding it in your initial view, the getMembers() function will also bring in other members, with zeros in the Exactitud RM key figure. So, you need to make sure that there is just one key figure in your data source.

2. That is tricky. If those 4 0PLANTS are always the same, we may need to establish in which order getMembers() is retrieving them, so that we apply the right values to each of your 4 text fields.

Let's try something like this for now:

var myArray = EXACTITUD_RM.getMembers("0PLANT", 10);

var myPlant = "";

myArray.forEach(function(element, index) {

myPlant = element.internalKey;

APPLICATION.alert(myPlant);

});

We will retrieve 10 members of your 0PLANT and display their keys - please note them down somewhere so you get the complete list. This will give us two important pieces of information:

a) how many members your getMembers() function is retrieving - we will know if it's just the 4 0PLANTs which we want (probably not), or some random 10 members (probably yes).

b) for the four members which we want, we will know in which order and which place they appear in our getMembers() function. Knowing that, we will write a function which will retrieve just the right getData for them.

0
Koen Hesters Mar 28, 2017 at 11:22 AM
0

Hi,

create a condition in the bex query, use the condition in design studio like you want, via code or just show it.

Grtz

Koen

Share
10 |10000 characters needed characters left characters exceeded