Forum Discussion

bibhuti10785's avatar
bibhuti10785
New Contributor
2 years ago
Solved

Mapper to retrieve a field value from optional json path

I have to extract "pw_cc__IsoCode_2__c" when in the payload "Country_of_Installation__r" is present.

Since both parent property Opportunity  and child property Country_of_Installation__r are optional field i need to  check if the node present before extracting the value. I tried in mapper  $.get('Opportunity').get('Country_of_Installation__r').get('pw_cc__IsoCode_2__c') but this throws can not invoke a method on null value.

Tried other javascript functions but most of them are not supported here.

can anyone help me with proper script.

[{
    "OpportunityId":"0063x00001bZVt8AAG",
    "Opportunity":
        {
            "Id":"0063x00001bZVt8AAG",
            "Country_of_Installation__r":
                {
                    "attributes":
                        {
                            "type":"aaaaaa",
                            "url":"/services/data/v60.0/bbbb"
                        },
                    "Id":"a4u120000008XpbAAE",
                    "pw_cc__IsoCode_2__c":"MZ"
                }
           
        }
}]
 
 
 
  • Hello bibhuti10785,

    You can with the following expression in a Mapper Snap:

    jsonPath($,"..pw_cc__IsoCode_2__c") != [] ? jsonPath($,"..pw_cc__IsoCode_2__c").pop() : null

    Attached below is a sample pipeline.

    Please let me know if this helps you!

    Regards,

    Aleksandar.

2 Replies

  • Hello bibhuti10785,

    You can with the following expression in a Mapper Snap:

    jsonPath($,"..pw_cc__IsoCode_2__c") != [] ? jsonPath($,"..pw_cc__IsoCode_2__c").pop() : null

    Attached below is a sample pipeline.

    Please let me know if this helps you!

    Regards,

    Aleksandar.

    • Aleksandar_A's avatar
      Aleksandar_A
      Contributor III

      You could also try with the following expression:

      $.hasPath("Opportunity.Country_of_Installation__r.pw_cc__IsoCode_2__c") ? $Opportunity.Country_of_Installation__r.pw_cc__IsoCode_2__c : null