Hide interface field if it has a null value

If a variable does not have a value save into it how do you hide it in the interface? 

This was my attempt at it using the showWhen variable: 

a!dateField(
label: "Tier 2 Findings",
labelPosition: "ABOVE",
value: ri!svcRequest.tier_two_date,
saveInto: {},
showWhen: if (ri!svcRequest.tier_two_date, true, false) ,
readOnly: true,
validations: {}
),

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    If you want to make any field hidden then definitely you can use showWhen parameter. Something like below,

    If(

    a!isNullOrEmpty(ri!svcRequest.tier_two_date),

    false,

    true

    )

    But why you don't have anything in save into ? What was the use case?

  • its for the summary view of a pervious application 

  • 0
    Certified Lead Developer

    showWhen requires a boolean response (or null, in which case it defaults to "true").  You seem to have this covered as your if() statement is configured to return a boolean value itself.

    However, your original if() statement is not really configured correctly in its first parameter.  The first parameter of an if() statement is expecting something that will evaluate as either TRUE or FALSE.  But for some reason you've passed in "ri!svcRequest.tier_two_date" - which would either return the date value (i assume), or blank.  Neither of those is a TRUE or FALSE value.  already provided you the answer to this next step, which is to actually do a null check on your date field, which will return the necessary TRUE or FALSE value - I just wanted to be sure you understand why this is needed instead of what you've done.

    Then as a final step: although an if() statement is useful in many, many cases - in a time like this you don't really need it.  You could simply set your showWhen parameter to a statement that evaluates to true/false itself.  In this case we would utilize the new "a!isNotNullOrEmpty()" function.  The end result would look like this:

    showWhen:a!isNotNullOrEmpty(ri!svcRequest.tier_two_date)

  • Another faster way to convert a null into false can be to wrap the variable in 'or()' function. 

  • 0
    Certified Senior Developer

    I hope You found a way to conditionally show a UI component.

    Incase if you don't have "showWhen" parameter for a certain component, then can you wrap the entire UI component which you want to hide conditionally in an if() function.

    if(

    a!isNullOrEmpty(ri!svcRequest.tier_two_date),

    {},

    a!dateField(
    label: "Tier 2 Findings",
    labelPosition: "ABOVE",
    value: ri!svcRequest.tier_two_date,
    saveInto: {},
    readOnly: true,
    validations: {}
    )

    )


    Assume that the a!dateField has no "showWhen" parameter.