Skip to Content

Hello,

I need to check if a value (personal number) is existing in the transaction OPS6.

For that I created a new flavor with two fields and a script into this transaction.

The first field is used to define the value to check and the second one to display the result of the script.

/wp-content/uploads/2015/11/img1_833665.jpg

The problem with my script is that the table is bigger as the screen and when I executed it, I have an error.

When I reduce my windows, I have the same error but the “rowIndex” is different.

/wp-content/uploads/2015/11/img2_833666.jpg

Here bellow I attached my script.

/wp-content/uploads/2015/11/script_833667.jpg

Does anyone have an idea to help me ?

Thanks

Dominique

To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

  1. Dominique Rochat Post author

    Thanks Steve,

    it’s work but now I want to use a value into this variable.

    I have a value on my script and I want to test if this value exist on this array.

    I use directly the command :

    var idx = contents.indexOf(pernr);

    or the function :

    function array_search(what, where){

    var index_du_tableau=-1

        for(elt in where){index_du_tableau++;

                 if (where[elt]==what){return index_du_tableau}

                             }

        index_du_tableau=-1;

        return index_du_tableau}

    var idx = array_search(pernr,contents);


    I have allways the value -1 as return even if the value exist.

    Can you tell me how to use the values of this array to continue to work with my script ?


    Thanks


    Dominique

    (0) 
    1. Steve Rumsby

      Each element of the “contents” array is actually an object with fields for each of the table columns. The wiki shows you the structure. You need to compare your “pernr” value not against the array element directly but against the matching field (table column).

      Steve.

      (0) 
      1. Dominique Rochat Post author

        Thanks Steve,

        I tried directly with the name of the table and the field but they doesn’t work.

        In the console, they are an array with different objects as you mentionned.

        On each object they are different fields

        /wp-content/uploads/2015/11/image1_837898.jpg

        I want do compare my variable (pernr) with the field V_TCJ04-VERNR.

        I created a loop to compare this value. When I execute my script with a fix value (1102 for example), the script is executed without errors but when I compare with the field, i have an error.

        What is the correct syntax to compare with this field ?

        Second question, what is the syntax to define the number of object included in my array for my loop “for” ?

        Many thanks for your help.

        Dominique

        (0) 
        1. Steve Rumsby

          You are comparing pernr against fields in the array, so you want something like:

          if(pernr == contents[i]["VERNR"]) {
               // ...
          }
          

          You’ll have to check the exact field name – “VERNR” is just a guess. Use the object inspector on the table column to see what the object ID is – the field name will be at the end. Or else use the browser debugger to look at the structure of the “contents” array once it has been created.

          Steve.

          (0) 
          1. Dominique Rochat Post author

            Thanks, it’s better I havn’t error anymore in my script but … He doesn’t works correctly.

            I think they doesn’t check correctly the value. I checked the name of the field (in the table and in the console -> see the screenshot below)  and he is correct.

            I try to add this value in the session.log but I have always an undefined value, that’s why I think the check isn’t correct.

            Dominique

            /wp-content/uploads/2015/11/image3_838048.jpg

            (0) 
            1. Steve Rumsby

              It looks like the field is actually called “V_TCJ04-VERNR” and not just “VERNR” so try:

              if(pernr == contents[i]["V_TCJ04-VERNR"]) {
                   // ...
              }
              

              Steve.

              (0) 
                  1. Dominique Rochat Post author

                    How NICE !!

                    Rookie mistake 😕


                    It’s work, I saw in the session logging that the loop run fine and the script can read the values. 🙂

                    I take your knowledge to ask you another question :
                    “how can I defined the number of objects into my array to specified the end of my loop”.
                    I tried with this command but they doesn’t work.

                    for (i; i < contents.length; i++)

                    Dominqiue


                    (0) 
                    1. Steve Rumsby

                      If I understand the question then your for-loop is correct, but the logic in the body of the loop is not. See my code in the comment below – does that help?

                      Steve.

                      (0) 
                1. Steve Rumsby

                  Here’s my script to do this. This is tested and works:

                  var pernr = session.findById("wnd[0]/usr/txtPersonas_1448464657180").text;
                  
                  var i;
                  for(i = 0; i < contents.length; i++) {
                       if(contents[i]["V_TCJ04-VERNR"] == pernr) {
                            session.findById("wnd[0]/usr/txtPersonas_1448464671888").text = "Yes";
                            break;
                       }
                  }
                  if(i == contents.length) {
                       session.findById("wnd[0]/usr/txtPersonas_1448464671888").text = "No";
                  }
                  

                  However, if you have a lot of responsible persons, reading the whole table can be a bit slow. We have a little over 3,000 entires in that table and a check for the first entry in the table takes about 14 seconds, which is almost all spent reading the table into the “contents” array. A check for an entry that does not exist, and which therefore requires reading through the entire “contents array”, takes 15 seconds, so the search is fairly quick in comparison to reading the data. Be aware of that. It looks from your screen shot, and the size of the bubble on the scroll bar, that you have fewer entries than we do.

                  I’d be inclined to think about implementing this test in a BAPI – it will likely be much faster.

                  Steve.

                  (0) 

Leave a Reply