Skip to Content
0
Former Member
Nov 08, 2017 at 06:58 AM

convert Lead as prospect partner(Customer type)

1270 Views Last edit Dec 27, 2017 at 05:46 AM 10 rev

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