Solved

Save DAC which is not part of the graph into database

  • 30 October 2022
  • 3 replies
  • 253 views

Userlevel 1

Hi everyone,

i am having my processing form which is calling external API to collect the data, the thing is that my saving into database is working, but i would like to use the data to save into Leads, when i use var graph = PXGraph.CreateInstance<LeadMaint>(); to create graph, i have created two DACs (one for the address and one CRLead) but i cannot insert them into database so that i can call “Actions.Save”...Can someone give me some guidence….

icon

Best answer by jinin 30 October 2022, 17:21

View original

3 replies

Userlevel 1

This is the approach which i have taken….but something does not work….

 

// Populate a local list variable.
            List<SAParticipant> list = new List<SAParticipant>();
            using (var ts = new PXTransactionScope())
            {
                int i = 0;

                // lead graph
                var leadGraph = PXGraph.CreateInstance<LeadMaint>();
                foreach (SAParticipant dacParticipant in adapter.Get<SAParticipant>())
                {
                    if (i > 1)
                        continue;

                    // get participant from the mapper
                    Participant extParticipant;
                    if (ParticipantsMapper.TryGetValue(dacParticipant, out extParticipant))
                    {
                        // first save address
                        Address address = new Address()
                        {
                            AddressLine1 = extParticipant.Street,
                            AddressLine2 = extParticipant.Street2,
                            City = extParticipant.City,
                            State = extParticipant.State,
                            CountryID = extParticipant.Country,
                            PostalCode = extParticipant.Zip
                        };

                        address = leadGraph.AddressCurrent.Insert(address);
                        leadGraph.Actions.PressSave();

                        // save lead
                        CRLead lead = new CRLead()
                        {
                            Title = extParticipant.Title,
                            FirstName = extParticipant.FirstName,
                            LastName = extParticipant.LastName,
                            FullName = extParticipant.Organization,
                            EMail = extParticipant.Email,
                            Fax = extParticipant.Fax,
                            Phone1 = extParticipant.Phone,
                            Phone2 = extParticipant.Mobile,
                            WebSite = extParticipant.Website,
                            Source = "Event",
                            DefAddressID = address.AddressID
                        };

                        lead = leadGraph.LeadCurrent.Insert(lead);
                        leadGraph.Actions.PressSave();


                        // save attachments

                        //if (order.Selected == true)
                        list.Add(dacParticipant);

                        // insert into view for saving

                        dacParticipant.Sapleadid = lead.ContactID;
                        Participants.Insert(dacParticipant);

                        i++;
                    }
                    ts.Complete();
                }
            }

            // save into database
            Actions.PressSave();

            return list;
        }

Userlevel 7
Badge +11

Hi @joni50para 

Can you please try the below steps,

  1.  Initialize new graph
  2. Insert the current lead first (This is the primary view of the graph)
  3. Then insert Address details.
  4. Save the graph.

 

Userlevel 1

Thank you Jini, i have tried that approach and it worked! 

i will post the working example when am finished, because i have to implement to add the attachments also

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved