How can i createAttriuteMap to map field value from one entity to another entity.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ashif Malayil
    Senior Member
    • Dec 2023
    • 172

    How can i createAttriuteMap to map field value from one entity to another entity.

    Previously i raised the same query, https://forum.espocrm.com/forum/gene...to-sales-order
    1. I have Billing and Shipping address fields in the Opportunity. While creating a Sales Order from the Opportunity, I want to fetch these fields before saving. Can I use attribute mapping for this?
    2. In the Opportunity Item, I have added some enum fields like Colour, Brand, and Model. After creating a Sales Order from the Opportunity, these fields are not mapping to the Sales Order item.
      Note: The same enum fields have been created in the Sales Order item as well. I tried mapping these through a "After Created" workflow, but it's not working.

    Can anyone help me resolve these two issues?
  • victor
    Active Community Member
    • Aug 2022
    • 728

    #2
    1. It is not clear why you need the Billing and Shipping address fields in the Opportunity. These fields are filled in the Account, which we relay to our Oppotunity. And then (when you create a Sales Order from Opportunity) these fields will be automatically filled in the created Sales Order (screenshot 1).
    2. Regarding transferring data from the the Opporunity Item Enum field to the similar Enum field of the Sales Order Item: no workflows are required. If there is a complete match in the Enum fields, the data is transferred automatically (screenshots 2 and 3).​
    Attached Files
    Last edited by victor; 09-13-2024, 02:50 PM.

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1250

      #3
      Hey for first question below is the code you need, just create a new clientDefs file for the Opportunity under custom folder and use this code below

      PHP Code:
      {
          "relationshipPanels": {
              "salesOrders": {
                  "createAttributeMap": {
                      "billingAddressCity": "addressCity",
                      "billingAddressStreet": "addressStreet",
                      "billingAddressPostalCode": "addressPostalCode",
                      "billingAddressState": "addressState",
                      "billingAddressCountry": "addressCountry",
                      "shippingAddressCity": "addressCity",
                      "shippingAddressStreet": "addressStreet",
                      "shippingAddressPostalCode": "addressPostalCode",
                      "shippingAddressState": "addressState",
                      "shippingAddressCountry": "addressCountry"
                  }
              }
          }
      }
      For second question, it is different you need workflow to do this or Hooks. Using worfklow you can loop through the existing items and create new ones etc
      Rabii
      Web Dev

      Comment

      • Ashif Malayil
        Senior Member
        • Dec 2023
        • 172

        #4
        Originally posted by victor
        1. It is not clear why you need the Billing and Shipping address fields in the Opportunity. These fields are filled in the Account, which we relay to our Oppotunity. And then (when you create a Sales Order from Opportunity) these fields will be automatically filled in the created Sales Order (screenshot 1).
        2. Regarding transferring data from the the Opporunity Item Enum field to the similar Enum field of the Sales Order Item: no workflows are required. If there is a complete match in the Enum fields, the data is transferred automatically (screenshots 2 and 3).​
        1. Actually we are not using Account module, Contact to Opportunity is our process flow.


        2. I followed the same steps and created exact matching enum fields in Opportunity Item and Sales Order item (screenshots 1 & 2).

        Please find the attached screenshots for the items panel in the Detail Layout (screenshots 3 & 4).

        i don't know, if i'm missing something. why these auto population is not working in my instance?
        Last edited by Ashif Malayil; 09-14-2024, 05:36 AM.

        Comment


        • victor
          victor commented
          Editing a comment
          i don't know, if i'm missing something. why these auto population is not working in my instance?
          In the first screenshot, the field is called "material", and in the second, "cMaterial".
      • Ashif Malayil
        Senior Member
        • Dec 2023
        • 172

        #5
        Originally posted by rabii
        Hey for first question below is the code you need, just create a new clientDefs file for the Opportunity under custom folder and use this code below

        PHP Code:
        {
        "relationshipPanels": {
        "salesOrders": {
        "createAttributeMap": {
        "billingAddressCity": "addressCity",
        "billingAddressStreet": "addressStreet",
        "billingAddressPostalCode": "addressPostalCode",
        "billingAddressState": "addressState",
        "billingAddressCountry": "addressCountry",
        "shippingAddressCity": "addressCity",
        "shippingAddressStreet": "addressStreet",
        "shippingAddressPostalCode": "addressPostalCode",
        "shippingAddressState": "addressState",
        "shippingAddressCountry": "addressCountry"
        }
        }
        }
        }
        For second question, it is different you need workflow to do this or Hooks. Using worfklow you can loop through the existing items and create new ones etc
        I have already added this script in the following path: custom/Espo/Custom/Resources/metadata/clientDefs/Opportunity.json (Screenshot 1).

        Please find the attached screenshots of the Detail View and Sales Order Detail (Small View) (Screenshots 2 & 3).

        As you can see in the (screenshot 3) still the fields are empty. please help me to fix this? Do i need to create new Opportunity.json instead of this existing Opportunity.json?
        Last edited by Ashif Malayil; 09-14-2024, 05:39 AM.

        Comment


        • rabii
          rabii commented
          Editing a comment
          make sure that the names of teh fields are correct on both sides. On dispatch entity it is billing address and shipping address so you should map the fields with proper names.
      • Ashif Malayil
        Senior Member
        • Dec 2023
        • 172

        #6
        rabii , the field name is correct, only the label has been changed. victor , for this issue, I also tried changing both field names to the same. However, in /application/Espo/Modules/Crm/Resources/metadata/entityDefs, SalesOrder.json is not there. In custom/Espo/Custom/Resources/metadata/entityDefs/, SalesOrder.json is present, but I am unable to find the Billing and Shipping address fields. How can I fix this issue?​

        Now the entity is:-
        Opportunity :- fields are Billing Name, Billing Address and Shipping Address
        Sales Order :- fields are Billing Name, Billing Address and Shipping Address

        Note : Only field labels are same not field names.
        Last edited by Ashif Malayil; 09-16-2024, 07:56 AM.

        Comment

        • Ashif Malayil
          Senior Member
          • Dec 2023
          • 172

          #7
          victor, thank you so much! I changed the field name from the back-end, and it's now getting mapped. However, the previous data is missing after the change. That's okay, I'll export and import it. The issue is that previously the field name could be whatever we wanted, but now it automatically adds a "c" before every field name.
          Last edited by Ashif Malayil; 09-16-2024, 04:52 AM.

          Comment

          Working...