# Conditions and the bo.is() Function

reviewed: 8 March 2025

Conditions

Conditions are a concept unique to CaseMaster. Conditions are designed to make complex where clauses easier to read, reuse and maintain.

Let us take a look at the following examples (and assume the client entity has a status attribute with options and where the value 3 means active):

bo.count( 'client', 'status=3' )
bo.count( 'client', '#is( "active" )' )

Most people will not know the various values of client.status by heart. The second option (which makes use of the conditions feature) is much easier to read and understand. Another bonus is that if there is ever the need to change the options of client.status, we only have change the active condition and instead of reviewing all queries in the system.

Condition are added to the entity script, just like attributes and methods.

condition active()
    return 'status=3'
end-condition

Conditions can get complex and themselves use conditions. Take the following real-life example:

condition month3CallReady()
    return '#is("active") & status=3 & gosiStartDate<>#null & gosiStartDate>={ addDay( today(), -182 ) }'
end-condition

Conditions can, just like methods, take parameters. Take a look at the following example:

condition myRelevantJourneys( what:'mine' )
    switch [what]
    case 'mine'
        set( 'return', '( advisor={ user() } | ( originaladvisor={ user() } & originaladvisor<>{ null() } ) )' )
    case 'mybranch'
        set( 'return', '#exists[ br/branch, #is("myBranches") ]' )
    else
        set( 'return', '( advisor={ user() } | ( originaladvisor={ user() } & originaladvisor<>{ null() } ) )' )
    end-switch
end-condition

And in use in the following snippet:

    // Additional code here
    iterator: iterator.ofEntity(
        entities: <
            <
                name: 'journey'
                entity: 'cd/journey'
                where: $concat(
                    'id>0 & branch={qs.get("branch")}',
                    '& #is("myRelevantJourneys", { qs.get("clShow") } )'
                )
    // Additional code here

Note: the condition feature is often not used to its full potential. Even in seasoned CaseMaster teams I come across highly complex where clauses repeated over and over again in a system. Do yourself (and the developers after you) a big favour and consider using conditions.

Using Conditions in Expressions: bo.is()

In the previous paragraph we have seen conditions in action in where clauses using the #is() function. You can also use conditions in expressions using the bo.is() function.

See the following example:

set( 'journey', bo.quickLoad( 'cd/journey', qs.get( 'journey' ) ) )

if bo.is( [journey], 'active' )
    // Code here when journey is active
end-if

<End of document>