Skip to main content
March 16, 2022
Question

Resolving Null variables

  • March 16, 2022
  • 4 replies
  • 0 views
In our system a user can enter up to 3 studies but only one is required. 
My current work around is saving any studies not entered to "N/A"

if(
isnull(ri!svcRequest.study_two),
{ a!save(ri!svcRequest.study_two, "N/A") },
{}
),
if(
isnull(ri!svcRequest.study_three),
{ a!save(ri!svcRequest.study_three, "N/A ") },
{}
),

Issues is In the follow up email it looks like this: 

We were pleased to support your review by performing additional analysis on studies: cat, N/A, N/A

How do I show and hide variables with null values so the sentence above only shows studies that are entered? 

We were pleased to support your review by performing additional analysis on studies: cat 

Side note: this is what the email expression looks like: 

=pv!svcRequest.study_one & ", " & pv!svcRequest.study_two & ", " & pv!svcRequest.study_three

    4 replies

    gopalk2865
    Participating Frequently
    March 16, 2022

    Hi, There could be multiple ways to implement what you are trying to do. I would suggest you to apply null check before concatenating these three variables. You can use nested If() .

    mikes0011
    Brainy
    March 16, 2022

    You would just wrap each one of the subsequent entries in its own if() statement, it doesn't really require nesting per se.  This would allow you to use either or both of "study_two" and "study_three", and inherently requires "study_one" to be filled in.

    pv!svcRequest.study_one &
    if(
      a!isNullOrEmpty(pv!svcRequest.study_two),
      null(),
      ", " & pv!svcRequest.study_two
    ) &
    if(
      a!isNullOrEmpty(pv!svcRequest.study_three),
      null(),
      ", " & pv!svcRequest.study_three
    )

    The Expression Guru
    March 16, 2022

    Awesome, I did this in the email in stead of the form, thank you for this! 

    harshitb6843
    March 17, 2022

    Hi there,

    When you're finally constructing this sentence for your email, use this code. 

    substitute(ri!variable, "N/A","")

    This will remove the "N/A" from your code.