Skip to main content
Solved

Save DAC which is not part of the graph into database

  • October 30, 2022
  • 3 replies
  • 390 views

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….

Best answer by jinin

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.

 

View original
Did this topic help you find an answer to your question?

3 replies

  • Author
  • Freshman I
  • 8 replies
  • October 30, 2022

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;
        }


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 706 replies
  • Answer
  • October 30, 2022

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.

 


  • Author
  • Freshman I
  • 8 replies
  • October 30, 2022

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings