cancel
Showing results for 
Search instead for 
Did you mean: 

Create Key: Pair value in mapper

akarsh
New Contributor III
Input Structure
[
{
"Id": "ABC",
"IFA_Number__c": "1"
},
{
"Id": "BCD",
"IFA_Number__c": "2"
}
]

I have to save this data in a key value format ( Ifanumber is key and ID is value) so that later in mapper I have to fetc fetch the respective ID based on IFA number. what's best way to do this?

2 ACCEPTED SOLUTIONS

Hello @akarsh,

You can try with grouping all of the documents into a single array, then using reduce to combine them in one object.

Please note that if you have duplicate keys through the documents, they will overwrite.

Please refer to the attached pipeline and let me know if this helps you.

 

Regards,

Aleksandar.

View solution in original post

You can try with the following expression:

$dataList.map(x => x.get('IfaNumber',null)).filter((x,ind,arr) => x != null && arr.indexOf(x) == ind)

Let me know if this helps.

Regards,

Aleksandar.

View solution in original post

11 REPLIES 11

Aleksandar_A
Contributor III

Hello @akarsh.

You can try with the following expression in a Mapper Snap:

{[$IFA_Number__c]:$Id}

Map this to $ and let me know if this helps you.

Regards,

Aleksandar.

akarsh
New Contributor III

How do I access this data later?  I saved it as $customerMappings and then later tried to use it in mapper as $customerMappings[$customerIFANumber] but got "property_map.settings.transformations.value.mappingTable.value[8].expression.value: Expression parsing failed near -- rIFANumber >> "] << (Reason: Unterminated string literal at line 1:36; Resolution: Insert the close quote character at the end of the string literal)"  error

akarsh
New Contributor III

As you suggested I created a mapper like this

akarsh_0-1705993137392.png

Output looks like this

akarsh_1-1705993186798.png

Is it possible to get the output in form of single json document like

 
{
"customerMappings": {
"1": "A",
"2":"B"
}
}

Hello @akarsh,

You can try with grouping all of the documents into a single array, then using reduce to combine them in one object.

Please note that if you have duplicate keys through the documents, they will overwrite.

Please refer to the attached pipeline and let me know if this helps you.

 

Regards,

Aleksandar.