Skip to main content
Answer

Save DAC which is not part of the graph into database

  • October 30, 2022
  • 3 replies
  • 437 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.

 

3 replies

  • Author
  • Freshman I
  • 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
  • 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
  • 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