Forum Discussion

amit_saroha's avatar
amit_saroha
New Contributor III
4 years ago

How to handle NULL

Hi,

I have the below expression but sometimes it can be NULL instead of ‘S’. Could you please suggest how to handle the NULL in the below expression?

$input0.final_document.Pipeline_Status==‘S’ && $input1.final_document.Pipeline_Status==‘S’ && $input2.final_document.Pipeline_Status==‘S’

6 Replies

  • Supratim's avatar
    Supratim
    Contributor III

    You can use $.hasOwnProperty(‘input0.final_document.Pipeline_Status’) It will gives you true if value is not null.

  • amit_saroha's avatar
    amit_saroha
    New Contributor III

    @Supratim, Thanks for the inputs. My requirement is to handle both things e.g. I want to assign the value ‘S’ in mapper if it’s NULL OR its S.

    How I can do it, please suggest.

    ($input0.final_document.Pipeline_Status==‘S’ OR NULL) && ($input1.final_document.Pipeline_Status==‘S’ OR NULL) && ($input2.final_document.Pipeline_Status==‘S’ OR NULL)

    • bojanvelevski's avatar
      bojanvelevski
      Valued Contributor

      You’re quite close:

      ($input0.final_document.Pipeline_Status=='S' || $input0.final_document.Pipeline_Status== null) && ($input1.final_document.Pipeline_Status=='S' || $input1.final_document.Pipeline_Status== null) && ($input2.final_document.Pipeline_Status=='S' || $input2.final_document.Pipeline_Status== null)

      Or, other thing that you can try is the following:

      $input0.final_document.Pipeline_Status matches 'S'|null && $input1.final_document.Pipeline_Status matches 'S'|null && $input2.final_document.Pipeline_Status matches 'S'|null

      • JensDeveloper's avatar
        JensDeveloper
        Contributor II

        Thank you @bojanvelevski for elaborating.

        I forgot to say that NULL needs to be in null because that’s so in snaplogic and what bojan gave as a solution should work

    • JensDeveloper's avatar
      JensDeveloper
      Contributor II

      Hi @amit.saroha
      You mean you want to fill the fields with S if it’s null?

      Then you should use an if else
      $input0.final_document.Pipeline_Status == NULL ? S : $input0.final_document.Pipeline_Status

  • amit_saroha's avatar
    amit_saroha
    New Contributor III

    @JensDeveloper - I have used the expression but it error out as below -

    Reason: com.snaplogic.cc.SnapCcException: Not starting pipeline as pipeline has prepare error. “{4a09e57e-fdc0-465f-9af9-2b8ed3314046={property_map.settings.routes.value[1].expression.value=[Expression parsing failed near – s != NULL >> ? << S : $inp (Reason: Mismatched input ‘?’ at line 1:143. Expecting one of: {, ‘||’, ‘&&’, ‘^’, ‘==’, ‘!=’, ‘>’, ‘<’, ‘>=’, ‘<=’, ‘+’, ‘-’, ‘', ‘/’, ‘%’, ‘instanceof’, ‘in’, ‘[’, ‘(’, ‘.’, PropertyRef}; Resolution: Please check expression syntax)], property_map.settings.routes.value[0].expression.value=[Expression parsing failed near – s == NULL >> ? << S : $inp (Reason: Mismatched input ‘?’ at line 1:143. Expecting one of: {, ‘||’, ‘&&’, ‘^’, ‘==’, ‘!=’, ‘>’, ‘<’, ‘>=’, ‘<=’, ‘+’, ‘-’, '’, ‘/’, ‘%’, ‘instanceof’, ‘in’, ‘[’, ‘(’, ‘.’, PropertyRef}; Resolution: Please check expression syntax)]}, 665a0695-e27a-425f-a665-c7de74c2f820={property_map.settings.routes.value[1].expression.value=[Expression parsing failed near – s != NULL >> ? << S : $inp (Reason: Mismatched input ‘?’ at line 1:143. Expecting one of: {, ‘||’, ‘&&’, ‘^’, ‘==’, ‘!=’, ‘>’, ‘<’, ‘>=’, ‘<=’, ‘+’, ‘-’, ‘', ‘/’, ‘%’, ‘instanceof’, ‘in’, ‘[’, ‘(’, ‘.’, PropertyRef}; Resolution: Please check expression syntax)], property_map.settings.routes.value[0].expression.value=[Expression parsing failed near – s == NULL >> ? << S : $inp (Reason: Mismatched input ‘?’ at line 1:143. Expecting one of: {, ‘||’, ‘&&’, ‘^’, ‘==’, ‘!=’, ‘>’, ‘<’, ‘>=’, ‘<=’, ‘+’, ‘-’, '’, ‘/’, ‘%’, ‘instanceof’, ‘in’, ‘[’, ‘(’, ‘.’, PropertyRef}; Resolution: Please check expression syntax)]}}”