Access value at path that may not exist

Options

Hi everyone

I have a Query All Records function that is grouping records by a value (user.role) and then counting the number of records in each group. The output is shown below. I want to access the number of records for a particular role in a subsequent function. There is a chance that the role that I want to access the count for ('worker') may not exist though. How do I access the number shown with the arrow if it exists?

Thanks.

Best Answer

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Answer ✓
    Options

    Yes,

    If it is a list then you can make a loop through the list and check for a user_role - worker and if that condition is true then get the count value

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    I think what you are looing for is "get" filter. it will allows you the get a value from a specific path and in case that path does not exists you can assign a value that should replace it, for example "null". This way you will not get the error that the path does not exists.

    Hope that helps

  • dorian
    dorian Member
    Options

    Thanks @Pawel Magdanski. But I want to get the value at one path in an object if the object exists. In this case, I need to check if an object exists with user_role = 'worker' and if that object exists, get the value at path user_role_count in that object.

    So perhaps its a two step process? First check if the object exists and then if it does, get the value at the path in the object?