wso2 / mi-vscode

Micro Integrator extension for Visual Studio Code
Apache License 2.0
2 stars 3 forks source link

Limitation in Mapping Fields Across Different Objects #16

Open kalaiyarasiganeshalingam opened 4 months ago

kalaiyarasiganeshalingam commented 4 months ago

Description: The output is generated by mapping fields from various objects in the input. However, the current mapping process does not support mapping across different objects.

Screenshot 2024-06-27 at 13 07 22

Affected Product Version: MI-4.3.0-alpha

OS, DB, other environment details and versions:

Steps to reproduce:

Reproduce the issue by importing the input and output schema using the provided data:

Input Json

{
   "owner":[
      {
         "ID":"005D0000000nVYVIA3",
         "name":"Paul",
         "city":"CA",
         "code":"94041",
         "country":"US"
      },
      {
         "ID":"005D0000000nVYVIA2",
         "name":"Smith",
         "city":"CA",
         "code":"94041",
         "country":"US"
      }
   ],
   "lead":[
      {
         "ID":"00QD000000FP14JMAU",
         "name":"Carl",
         "city":"NC",
         "code":"97788",
         "country":"US"
      },
      {
         "ID":"00QD000000FP14JMAT",
         "name":"Carl",
         "city":"NC",
         "code":"97788",
         "country":"US"
      }
   ],
   "sendNotificationEmail":"true",
   "convertedStatus":"Qualified",
   "doNotCreateOpportunity":"true",
   "opportunityName":"Partner Opportunity",
   "overwriteLeadSource":"true",
   "sessionId":"QwWsHJyTPW.1pd0_jXlNKOSU"
}

Output XML


<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
    <soapenv:Header>
        <urn:SessionHeader>
            <urn:sessionId>QwWsHJyTPW.1pd0_jXlNKOSU</urn:sessionId>
        </urn:SessionHeader>
    </soapenv:Header>
    <soapenv:Body>
        <urn:convertLead>
            <urn:leadConverts>
                <urn:convertedStatus>Qualified</urn:convertedStatus>
                <urn:doNotCreateOpportunity>true</urn:doNotCreateOpportunity>
                <urn:leadId>00QD000000FP14JMAU</urn:leadId>
                <urn:opportunityName>Partner Opportunity</urn:opportunityName>
                <urn:ownerId>005D0000000nVYVIA3</urn:ownerId>
                <urn:sendNotificationEmail>true</urn:sendNotificationEmail>
            </urn:leadConverts>
            <urn:leadConverts>
                <urn:convertedStatus>Qualified</urn:convertedStatus>
                <urn:doNotCreateOpportunity>true</urn:doNotCreateOpportunity>
                <urn:leadId>00QD000000FP14JMAT</urn:leadId>
                <urn:opportunityName>Partner Opportunity</urn:opportunityName>
                <urn:ownerId>005D0000000nVYVIA2</urn:ownerId>
                <urn:sendNotificationEmail>true</urn:sendNotificationEmail>
            </urn:leadConverts>
        </urn:convertLead>
    </soapenv:Body>
</soapenv:Envelope>
``
madushajg commented 3 months ago

@kalaiyarasiganeshalingam currently this is not achievable by purely using the visual editor. However, if you add a custom function at the source file, you could use the visual mapper for rest of the mappings.

  1. Create a custom function at the source file

https://github.com/user-attachments/assets/20678ef1-559a-4a37-92fe-bc115ecb1374

you could write a function like below

function mergeOwnersAndLeads(owners: Root["owner"], leads: Root["lead"]) {
   return owners.map((owner, index) => ({
       ...owner,
       ...leads[index]
   }));
}
  1. Create a sub mapping to declare a variable to keep merged array

https://github.com/user-attachments/assets/079ae8a1-092b-4088-9971-0a59ff098c34

  1. Map sub mapping to output array with a map function and focus into it to do further mappings

https://github.com/user-attachments/assets/f9e9516e-9f36-456f-aaee-788c46069ae3

We are looking into ways of addressing these kinds of scenarios and will come up with a proper solution. Until that you can follow the above steps to achieve your requirement.