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,
- Initialize new graph
- Insert the current lead first (This is the primary view of the graph)
- Then insert Address details.
- 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