Help with retrieving the 'status' field in a formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abidoss
    Senior Member
    • Mar 2023
    • 231

    Help with retrieving the 'status' field in a formula

    Hello once again, please, can someone tell me where the issue is in this forum? I can't retrieve the "status" field even though it exists in the information.

    PHP Code:
    
    
    
    $vacancesesIds = vacancesesIds;
    
    if (array\length($vacancesesIds) > 0) {
        $premierId = array\at($vacancesesIds, 0);
    
        $informations = json\encode(record\fetch('Vacances', $premierId));
       output\printLine($informations);
      
        if (array\length($informations, "status")) {
            $status = array\get($informations, 'status');
            output\printLine("The status associated with the ID is: $status");
            
        } else {
            output\printLine("The 'status' field is not present in the information.");
        }
    } else {
        output\printLine("The list of vacationIds is empty.");
    }
    
    
  • Firyo
    Senior Member
    • Jun 2022
    • 135

    #2
    Hi,

    I can't find the documentation about the "get" function inside the "array" category.
    The "at" exists but not the "get" one.

    Are you sure you are using the correct function to get the "status" field inside your "Information ?


    Regards,
    Firyo.

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1264

      #3
      Not sure why you make it difficult using that code, i would do something like below:

      PHP Code:
      $vacancesesIds = vacancesesIds;
      
      if (array\length($vacancesesIds) > 0) {
          
          $vanceId = record\fetch('Vacances', array\at($vacancesesIds, 0));
      
          if ($vanceId) {
              $status = object\get($vanceId, 'status');
          }
        
          if ($status) {
              output\printLine("The status associated with the ID is: ");
              output\print($status);
          }
          else
          {
              output\printLine("The 'status' field is not present in the information.");
          }
      }
      else {
          output\printLine("The list of vacationIds is empty.");
      }
      Rabii
      Web Dev

      Comment


      • esforim
        esforim commented
        Editing a comment
        Curious, what the point of this?

        > $vacancesesIds = vacancesesIds;

      • rabii
        rabii commented
        Editing a comment
        Nothing just used it as he used it in the code. tbh it would be easier to just use vacancesesIds directly without assigning it to a variable.

      • esforim
        esforim commented
        Editing a comment
        Cool, I thought it was some hidden trick when using formula.

        Like you guys would just
        if ($vanceId) whereas me I would probably do something like this? if ($vanceId=='true')
    • abidoss
      Senior Member
      • Mar 2023
      • 231

      #4
      Thank you, Rabiiii. You always remain an excellent teacher.

      Comment

      Working...