Skip to main content

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

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


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.

 


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