Error in array/IndexOf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esendino
    Senior Member
    • May 2019
    • 158

    Error in array/IndexOf

    Hi.

    When it doesn't find the value in the array it is not returning null. Is returning something else.

    To test this I wrote this script

    $testList = list(1,2,3,4,5,6);

    $verify = 9;

    $position = array\indexOf($testList, $verify);


    $answer = 'unanswered';
    ifThen($position > 0,
    $answer = '>0');

    ifThen($position == 0,
    $answer = '0');

    ifThen($position == null,
    $answer = 'null');

    ifThen($position == '',
    $answer = 'nothing');


    //********** INICIO LOG DE PRUEBAS
    $tstDescription = null;
    $tstName = "Test 1 ";
    $tstDescription = string\concatenate(
    ' $position ', $position ,
    ' $verify ', $verify ,
    ' $answer ', $answer ,
    ' $testList ', array\join($testList, '-') ,
    " ");
    $tstLogId = record\create('LogPruebas',
    'name', $tstName,
    'description', $tstDescription);
    //*********** FIN LOG DE PRUEBAS​


    I ran this script changing the line with the verify line to

    $verify = 1;
    $verify = 3;
    $verify = 9;

    And he output was:

    Click image for larger version

Name:	image.png
Views:	151
Size:	7.9 KB
ID:	97727

    So when $verify = 9; ir shows $position apparentely as a null, but when I ask if $position == null, it doesn't make $answer = 'null'

  • yuri
    Member
    • Mar 2014
    • 8453

    #2
    Code:
    $index = array\indexOf(list(0, 1), 2);
    
    if ($index == null) {
        output\print('is null');
    }​
    prints "is null"
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • yuri
      Member
      • Mar 2014
      • 8453

      #3
      The version is required in bug reports. https://forum.espocrm.com/forum/bug-...o-report-a-bug I move the post out of bug reports.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • Jakub Grufik
        Senior Member
        • Aug 2022
        • 361

        #4
        Hey for me it works just fine...
        Click image for larger version

Name:	image.png
Views:	120
Size:	35.7 KB
ID:	97763

        Comment

        • Jakub Grufik
          Senior Member
          • Aug 2022
          • 361

          #5
          Tried also copy your code and it works fine for me

          Click image for larger version

Name:	image.png
Views:	117
Size:	41.1 KB
ID:	97766
          Attached Files

          Comment

          Working...