Skip to Content
0

convert Lead as prospect partner(Customer type)

Nov 08, 2017 at 06:58 AM

224

avatar image
Former Member

Hi Experts,

I want to convert Lead as prospect partner .

prospect partner in Customer has code “ZPRT”

I am getting the following error .

  • Changing the field not possible; field does not match partner category 2

I have resolved the above error but partner object not created..

First we need to create Role then only create prospect.

Category 1 is for person creation and category 2 for organization creation.

Either only one we need to specify.

For example:

elCustomerRoot.CategoryCode= "1";

elCustCurrentCommon.Person.Name.FamilyName = "TestnameSrinivas";

elCustCurrentCommon.Person.Name.FamilyName = "TestnameBorra";

or

elCustomerRoot.CategoryCode= "2";

elCustCurrentCommon.Organisation.Name.FirstLineName="SrinivasIBM";

Please find the following code and help me how to proceed on this.

Zlead.XBO

import AP.Common.GDT;

import AP.CRM.Global;

[Extension] businessobject AP.CRM.Global:Lead raises PartnerCreationFailed,PartnerConversionFailed,PartnerConvertedSuccess,DuplicateLeadFound{

// You must activate this business object before you can access the extension fields

// or messages in script files, forms, and screens.

node Party {

}

node Item {

}

message PartnerCreationFailed text "Account or Partner already created with this company name ";

message DuplicateLeadFound text "This Lead has Duplicate company name ";

message PartnerConversionFailed text "Partner Created already or Lead associated to Account.";

message PartnerConvertedSuccess text "Partner is Converted successfully";

element PartnerIndicator : Indicator= true;

element isPartnerDisable : Indicator= false;

action ConvertPartnerAndContact;

}

Custom Action:LeadToPartnerAndContactConversion.ABSL

import ABSL;

import AP.FO.BusinessPartner.Global;

import AP.CRM.Global as crm;

import AP.FO.Address.Global;

import AP.FO.BusinessPartnerRelationship.Global;

import AP.PC.ActivityManagement.Global;

if(!this.ID.IsInitial())

{

var LeanLead : crm:LeanLead;

LeanLead = crm:LeanLead.Retrieve(this.ID);

var isLeadConvertedToAccount = true;

var qryLead_Root_QueryByElements;

var selParamsLead_Root_QueryByElements;

var colQryResult;

var instLead;

// Lead: define query and parameters to be used for retrieval of data

qryLead_Root_QueryByElements = Lead.QueryByElements;

selParamsLead_Root_QueryByElements = qryLead_Root_QueryByElements.CreateSelectionParams();

selParamsLead_Root_QueryByElements.Add(qryLead_Root_QueryByElements.PartySortingFormattedName.content, "I","EQ",LeanLead.Organisation.FirstLineName);

// Lead: execute the query

colQryResult = qryLead_Root_QueryByElements.Execute(selParamsLead_Root_QueryByElements);

var leadCount = colQryResult.Count();

if(leadCount > 1)

{

foreach (var leadQry in colQryResult)

{

var LeanLeadDuplicate = crm:LeanLead.Retrieve(leadQry.ID);

var LLConversionInformation = LeanLeadDuplicate.ConversionInformation;

if(LLConversionInformation.IsSet())

{

isLeadConvertedToAccount = false;

raise DuplicateLeadFound.Create("E");

}

}

}

var query;

var selParams;

var queryResult;

query = Customer.QueryByBusinessObjectCustomer;

selParams = query.CreateSelectionParams();

// Retrieve customer by query identification

selParams.Add(query.CommonSortingFormattedName,"I","EQ", LeanLead.Organisation.FirstLineName);

queryResult = query.Execute(selParams);

var customerCount = queryResult.Count();

if(customerCount > 0)

{

isLeadConvertedToAccount = false;

raise PartnerCreationFailed.Create("E");

}

if(isLeadConvertedToAccount)

{

var leadStatus = this.Status.UserStatusCode.GetDescription();

if(leadStatus.Matches("Contacted") || leadStatus.Matches("Qualified"))

{

this.isPartnerDisable = true;

}else if(leadStatus.Matches("Open") || leadStatus.Matches("Rejected"))

{

this.isPartnerDisable = false;

}

// instance of object Lean Lead

var PartnerFlag = true;

// instance of object Lean Lead

var party = this.Party;

//filter the partner party.

var PartnerParty = this.Party.Where(n=>n.RoleCode=="ZPP");

//this count is more than zero means partner party is already created and partner creation fail.

if(PartnerParty.Count() > 0)

{

PartnerFlag = false;

this.PartnerIndicator = false;

raise PartnerConversionFailed.Create("E");

}

//Once the customer or account is created system is mainting the information in ConversionInformation

//once account is already created then not allow to create partner.

var ConversionInformation = LeanLead.ConversionInformation;

if(ConversionInformation.IsSet())

{

if(!ConversionInformation.TargetCustomerInternalID.IsInitial())

{

this.PartnerIndicator = false;

PartnerFlag = false;

raise PartnerCreationFailed.Create("E");

}

}

if(PartnerFlag)

{

// define root node

var elCustomerRoot: elementsof Customer;

var newCustomer;

elCustomerRoot.CategoryCode= "2";

newCustomer = Customer.Create(elCustomerRoot);

// set the customer new role code specific to partner and crearte customer role.

var elCustRole: elementsof newCustomer.Role;

elCustRole.RoleCode.content = "ZPART";

newCustomer.CustomerRole.Create(elCustRole);

// set the party new role code specific to partner and crearte customer role.

var elePartnerParty: elementsof this.Party;

elePartnerParty.RoleCode="ZPP";

elePartnerParty.PartyKey.PartyID.content=newCustomer.InternalID;

this.Party.Create(elePartnerParty);

///LeanLead.bu

// set the party new role code specific to partner and crearte customer role.

var elCustBussChars: elementsof newCustomer.CurrentBusinessCharacters;

elCustBussChars.ProspectIndicator= true;

newCustomer.CurrentBusinessCharacters.Create(elCustBussChars);

//set the Organisation name in currentcommon node and crearte CurrentCommon node.

var elCustCurrentCommon: elementsof Customer.Common;

elCustCurrentCommon.Organisation.Name.FirstLineName=LeanLead.Organisation.FirstLineName;

newCustomer.CurrentCommon.Create(elCustCurrentCommon);

// set the Organisation name to common node because once current common is created then common node also create.

if(newCustomer.Common.Count()>0)

{

var CurrCommon = newCustomer.CurrentCommon;

var currCommonName = CurrCommon.Organisation.Name.FirstLineName;

newCustomer.Common.GetFirst().Organisation.Name.FirstLineName = currCommonName;

}

// set and create ABCClassifications Node

var elCustABCClassi: elementsof newCustomer.ABCClassifications;

elCustABCClassi.CustomerABCClassificationCode= LeanLead.Organisation.AccountABCClassificationCode;

newCustomer.ABCClassifications.Create(elCustABCClassi);

// set partner address and personal information

var newAddressInfo = newCustomer.AddressInformation.Create();

var newPostalAddress = newAddressInfo.Address.DefaultPostalAddressRepresentation.Create();

newPostalAddress.StreetName = LeanLead.Address.PostalAddressElements.StreetName;

newPostalAddress.CityName = LeanLead.Address.PostalAddressElements.CityName;

newPostalAddress.CountyName = LeanLead.Address.PostalAddressElements.CountryCode.GetDescription();

newPostalAddress.CountryCode = LeanLead.Address.PostalAddressElements.CountryCode;

newPostalAddress.StreetPostalCode=LeanLead.Address.PostalAddressElements.StreetPostalCode;

var DefaultEMailAddress = newAddressInfo.Address.DefaultEMail.Create();

DefaultEMailAddress.URI=LeanLead.Address.EmailURI;

//set Owner of the partner.

var eleCurrentEmployeeResponsible: elementsof newCustomer.CurrentEmployeeResponsible;

eleCurrentEmployeeResponsible.EmployeeUUID =this.ResponsibleEmployeeParty.PartyUUID;

newCustomer.CurrentEmployeeResponsible.Create(eleCurrentEmployeeResponsible);

//set Relationship of the partner or to set main contact

var eleRelationship : elementsof newCustomer.Relationship;

eleRelationship.RoleCode.content = "BUR001-1";

var PartyContactParty = this.ProspectParty.PartyContactParty;

var PartyID = PartyContactParty.GetFirst().PartyKey.PartyID.RemoveLeadingZeros();

eleRelationship.RelationshipBusinessPartnerUUID=this.Party.MainPartyContactParty.GetFirst().PartyUUID;

newCustomer.Relationship.Create(eleRelationship);

newCustomer.CurrentDefaultHasContactPerson.BusinessPartnerRelationship.SecondBusinessPartner.CurrentDefaultIsContactPersonFor.Delete();

if(!LeanLead.Address.EmailURI.IsInitial())

{

var DefaultEMail =newCustomer.CurrentDefaultHasContactPerson.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultEMail.Create();

DefaultEMail.URI=LeanLead.Address.EmailURI;

}

if(this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultConventionalPhone.IsSet())

{

var DefaultConventionalPhone =newCustomer.CurrentDefaultHasContactPerson.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultConventionalPhone.Create();

DefaultConventionalPhone.FormattedNumberDescription=this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultConventionalPhone.FormattedNumberDescription;

}

if(this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultMobilePhone.IsSet())

{

var DefaultMobilePhone =newCustomer.CurrentDefaultHasContactPerson.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultMobilePhone.Create();

DefaultMobilePhone.FormattedNumberDescription=this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultMobilePhone.FormattedNumberDescription;

}

if(this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultFacsimile.IsSet())

{

var DefaultFacsimile =newCustomer.CurrentDefaultHasContactPerson.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultFacsimile.Create();

DefaultFacsimile.FormattedNumberDescription=this.ProspectParty.PartyContactParty.GetFirst().AddressSnapshot.DefaultFacsimile.FormattedNumberDescription;

}

//to convert contact.

var cont_uuid = this.Party.MainPartyContactParty.GetFirst().PartyUUID; //Contact UUID

var cust_uuid = this.Party.GetFirst().PartyUUID; //Account UUID

if (!cont_uuid.IsInitial() && !cust_uuid.IsInitial())

{

LeanLead.ConvertStatus(cont_uuid);

// LeanLead.ConvertStatus(cust_uuid,cont_uuid);

}

newCustomer.Activate();

//to invisible to partner action once partner is created and this is one way to stop duplicate partner.

this.PartnerIndicator= false;

//show success message once partner is created.

raise PartnerConvertedSuccess.Create("S");

}

}

}

Event-AfterModify.absl

import ABSL;

import AP.CRM.Global as crm;

if(!this.ID.IsInitial())

{

var LeanLead = crm:LeanLead.Retrieve( this.ID );

var leadStatus = this.Status.UserStatusCode.GetDescription();

if(leadStatus.Matches("Contacted") || leadStatus.Matches("Qualified"))

{

this.isPartnerDisable = true;

}else if(leadStatus.Matches("Open") || leadStatus.Matches("Rejected"))

{

this.isPartnerDisable = false;

}

var party = this.Party;

var PartnerIndicator = this.PartnerIndicator;

var PartnerParty = this.Party.Where(n=>n.RoleCode=="ZPP");

// if the PartnerParty count exists means custom party partner1 is already Created.

//because of this check ,can be avoid the duplicate partner .

if(PartnerParty.Count() > 0)

{

this.PartnerIndicator = false;

}

//this ProspectParty is set means lead is converted to account.

//because of this check ,can be avoid the duplicate partner

var ConversionInformation = LeanLead.ConversionInformation;

if(ConversionInformation.IsSet())

{

if(!ConversionInformation.TargetCustomerInternalID.IsInitial())

{

this.PartnerIndicator = false;

}

}

//this ProspectParty is set means lead is converted to account or assoicated to account.

//because of this check ,can be avoid the duplicate partner

var ProspectParty= LeanLead.ProspectParty;

if(ProspectParty.IsSet())

{

this.PartnerIndicator = false;

}

}

Thanks & Regards,

SRINIVAS BORRA

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Jonathan El-Haddad Nov 09, 2017 at 01:30 PM
0

Hi Srinivas,

If I am understanding correctly you want to update or create a customer from a LeanLead?

If so then you actually will not be to perform any updates or creations from the LeanLead object as the customer object is in a different deployment unit.

To achieve this you need to create a custom BO and use an internal communication to communicate from the Lead object and pass all the relevant information to that BO, then you can add your logic there to create or update the customer.

Hope this helps,

Jon

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 09, 2017 at 06:15 PM
0

Hi Jon,

Thanks for your reply.

I have done the same way.

I have created Custom Bo and created Custom EC is binding with lead IT header and passed Lead Id to custom Bo.

In custom BO has an action, above code is that only.

From Lead ID ,I have retrieve Lead Object with that I can assign to new partner (customer).

But now I have resolved the errors but new partner (customer) object is not created in account.

Thanks & Regards,

SRINIVAS BORRA

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 13, 2017 at 12:47 PM
0

Hi Jon,

I am able to convert lead customer .

Whenever creating current common in customer automatically common also will create so we need assign name to common also.

var elCustBussChars: elementsof newCustomer.CurrentBusinessCharacters;

elCustBussChars.ProspectIndicator= true;

newCustomer.CurrentBusinessCharacters.Create(elCustBussChars);

Please find the following code.

if(newCustomer.Common.Count()>0) {

var CurrCommon = newCustomer.CurrentCommon;

var currCommonName = CurrCommon.Organisation.Name.FirstLineName;

var common = newCustomer.Common.GetFirst();

var commonName = common.Organisation.Name.FirstLineName;

common.Organisation.Name.FirstLineName = currCommonName;

}

But I am facing double issue.

I want to prevent creating Duplicate customer.

Please help on this.

Thanks

Srinivas Borra

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Srinivas,

Happy to hear that you are able to create customers now!

Sounds like your script is being called twice - My advise to to just skim through the code to check if our are calling the business object more than 1 time, as I've seen this to be the cause for so many double executions.

Thanks

Jon

0
avatar image
Former Member Nov 23, 2017 at 09:13 AM
0

Hi Jon,

Finally I have completed this and restricted the duplicate account and partner.

I have updated all the code in the above thread.

Thanks & Regards,

SRINIVAS BORRA

Share
10 |10000 characters needed characters left characters exceeded