cancel
Showing results for 
Search instead for 
Did you mean: 

Setting the employee via custom code

chrisstokes4
Explorer
0 Kudos

Hi all,

We have some custom code which sets the customer on a B2C ticket generated from an incoming email by reading the body, extracting the sender and overwriting the original customer.

The email body looks like this:

________________________________
From: Referencing
Sent: 05 August 2022 13:07:41 (UTC+00:00) Dublin, Edinburgh, Lisbon, London
To: hrteam@mail.com
Subject: Reference Request

Sender = onlinereferencing@referencing.com

We want to do the same for an employee support ticket but the code doesn't work. I'm really not an expert and looking for support to see if its easy to amend the code for this scenario?

Thanks

Chris

Code is:

import ABSL;

import AP.FO.BusinessPartner.Global;

var TicketTextCollTextDesc;

var TicketTextCollTextValue;

var TicketTextCollText;

var TicketTextColl = this.TextCollection;

if(TicketTextColl.IsSet()){

TicketTextCollText = TicketTextColl.Text.Where(n => n.TypeCode.content == "10004");

if(TicketTextCollText.Count() > 0){

if(TicketTextCollText.GetFirst().TextContent.IsSet()){

TicketTextCollTextValue = TicketTextCollText.GetFirst().TextContent;

if(TicketTextCollTextValue.IsSet()){

TicketTextCollTextDesc = TicketTextCollTextValue.Text.content;

}

}

}

}

var TicketTextCollTextDescLength;

var FromPos;

var ToPos;

var MailfromDesc;

//Customer root definition

var elCustomerRoot: elementsof Customer;

var newCustomer;

// Activity: define party node

var elActivityParty : elementsof ServiceRequest.Party;

var instParty;

var FindInst;

if(this.IsSet()){

this.ZsenderChangeIndicator = true;

if(!TicketTextCollTextDesc.IsInitial()){

TicketTextCollTextDescLength = TicketTextCollTextDesc.Length();

FromPos = TicketTextCollTextDesc.Find("Sender");

if(FromPos >= 0 && TicketTextCollTextDescLength >= 0){

FromPos = FromPos + 9;

MailfromDesc = TicketTextCollTextDesc.Substring(FromPos , ((TicketTextCollTextDescLength - FromPos)));

if(!MailfromDesc.IsInitial()){

var SubStrPos = MailfromDesc.Find("\n");

if(SubStrPos > 0){

MailfromDesc = MailfromDesc.Substring(0,SubStrPos);

}

if((MailfromDesc.Find("@") > 0)&&(MailfromDesc.Find(".") > 0)){

if((MailfromDesc.Find("(") >= 0) || (MailfromDesc.Find(")") >= 0)){

var OpenPos = MailfromDesc.Find("(");

var DescLength = MailfromDesc.Length();

var ClosePos = MailfromDesc.Find(")");

if(OpenPos >= 0 ){

OpenPos = OpenPos+1;

if(ClosePos < 0 ){

ClosePos = DescLength;

}

MailfromDesc = MailfromDesc.Substring(OpenPos,(ClosePos-OpenPos));

}

}

if(!MailfromDesc.IsInitial()){

if((MailfromDesc.Find("@") > 0)&&(MailfromDesc.Find(".") > 0)){

this.ZSender.content = MailfromDesc;

}

if(!this.ZSender.IsInitial()){

var CustomerQuery = Customer.QueryByCommunicationData;

var CustomerParameter = CustomerQuery.CreateSelectionParams();

CustomerParameter.Add( CustomerQuery.EMailURI.content, "I", "EQ", this.ZSender.content);

var ResultCustomer = CustomerQuery.Execute(CustomerParameter);

if (ResultCustomer.Count() == 0 ){

elCustomerRoot.CategoryCode = "1";

newCustomer = Customer.Create(elCustomerRoot);

newCustomer.CurrentBusinessCharacters.CustomerIndicator = true;

newCustomer.CurrentCommon.Person.Name.FamilyName = this.ZSender.content;

newCustomer.CurrentDefaultAddressInformation.Create();

if(newCustomer.CurrentDefaultAddressInformation.IsSet()){

newCustomer.CurrentDefaultAddressInformation.Address.Create();

if(newCustomer.CurrentDefaultAddressInformation.Address.IsSet()){

newCustomer.CurrentDefaultAddressInformation.Address.DefaultEMail.Create();

if(newCustomer.CurrentDefaultAddressInformation.Address.DefaultEMail.IsSet()){

newCustomer.CurrentDefaultAddressInformation.Address.DefaultEMail.URI.content = this.ZSender.content;

}

}

}

this.BuyerParty.Delete();

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

this.BuyerParty.Create(elActivityParty);

this.BuyerParty.UsedAddress.DefaultEMail.Create().URI.content = this.ZSender.content;

}

else if(ResultCustomer.Count() > 0){

this.BuyerParty.Delete();

elActivityParty.PartyKey.PartyID.content = ResultCustomer.GetFirst().InternalID;

instParty = this.BuyerParty.Create(elActivityParty);

}

}

}

}

else{

raise ZINVALID.Create("E","Mail ID found from the description is not Allowed to create ticket");

}

}

else {

raise ZINVALID.Create("E","Mail ID found from the description is not valid");

}

}

}

}

Accepted Solutions (0)

Answers (0)