Follow

BUP - Auto-fill first and last name of contact when entering contact name

Important Notes

The samples and information below is provided without a warranty of any kind. This post is for informational purposes and coresystems ag assumes no responsibility for errors or omissions in the information provided.


Purpose

Attached is one customize optimizer rule that will split the Contact ID Field under Contact Persons in the Business Partner Master Data form. The rule takes the first word up to the first space and places that text into the First Name field and then everything after the space will be placed in the Last Name field automatically when entering or adjusting the contact name.

Since the contact name is usually a combination of first and last name it makes sense to fill these fields automatically instead of the user having to paste it in.


Requirements

The sample requires coresuite Version 3.50 or higher, and SAP Business One 8.8 or higher.


Procedure to use this small solution

  1. Download the attached file FAQ_10154_Auto-fill_first_and_last_name_of_contact_from_name.cocu
  2. Import in SAP Business One via > Administration > Add-Ons > coresuite customize > Import / Export > Import rules. In the message box, select “All Active”. Click on “Import”.
To check the rule in action:
  1. Open an existing Business Partner and view the contacts
  2. Modify the contact name of an existing contact
  3. Enter tabulator key or click somewhere else and see that the first name and last name of the contact have changed automatically.


Procedure to adjust this small solution

Could be used for other fields where the combination of several fields is stored in another field.

Preview Sample (Optimizer Rule C#):

string ruleName = pVal.RuleInfo.RuleName.ToString();
string errorMessage = "Error in Optimizer Rule '" + ruleName + "'";
try
{
Matrix m = Matrix.GetFromUID(pVal.Form, "107");
string name = m.GetValue("1", 0).Trim();
int count = name.Length - name.Replace(" ", "").Length;
if (count > 0) // does a space exist?
{
string[] myValues = name.Split(' ');
string firstName = "";
string lastName = "";
lastName = myValues[0];
if (count == 1)
firstName = myValues[1];
else if (count == 2)
firstName = myValues[1] + " " + myValues[2];
else
firstName = myValues[1] + " " + myValues[2] + " " + myValues[3];
m.SetValue("480000057", 0,lastName );
m.SetValue("480000059", 0, firstName );
}
else // if no space exist, assumption: it is only a first name
{
m.SetValue("480000057", 0, name);
m.SetValue("480000059", 0, "");
}
return true;
}
catch (System.Exception exe)
{
StatusBar.WriteError(errorMessage + ": " + exe.Message);
Debug.WriteMessage(errorMessage + ": " + exe.Message, Debug.DebugLevel.Exception);
}
return true;
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.