Customer name already exists

I cant add the same customer name i get error Customer name already exists. Can I have the phone number as the primary field. I already have customers in the database so is it possible to change existing customers also. I changed Entity Types, Primary Field Name to Phone but still wont let me add the same customer name?

Primary Field Name is just what you call the entity name, the software will just think that the column which was customer name is now customer number.
It doesnt change which column is the primarry field.
Given you already have a list of customers you might have dificulties changin the primary field.
How many customers in your list already?

Another forum member might have sugestion for a script to switch the data in the entities list columns to allow the number to be ion the primary field column…

I have about 100 customers.

I believe you will need to use SQL to change this, and I don’t know the ramifications of making such an update.

This is a basic proof of concept script… it basically replaces the Primary field with the Phone Number data, and updates the Custom Data to remove the Phone and replace it with the Customer Name.

USE [SambaPOS5]

-- set these values as necessary
declare @phoneNumLength int = 9
declare @phoneFieldName nvarchar(100) = 'Phone'
declare @entType varchar(100) = 'Customers'

-- nothing else to set beyond here
declare @phoneFieldNameLen int = LEN(@phoneFieldName)+12

declare @ent table (
 [EId] int not null
,[Etype] int not null
,[EPhone] varchar(255) null
,[EData] nvarchar(max) null
,[EName] varchar(255) null
,[Eprimary] varchar(255) null

,substring([customdata], charindex('"'+@phoneFieldName+'"',[CustomData])+@phoneFieldNameLen,@phoneNumLength) as i
FROM [dbo].[Entities]
where [EntityTypeId]=(SELECT [Id] FROM [EntityTypes] WHERE [Name]=@entType)

UPDATE @ent SET [Eprimary]=[EPhone]

UPDATE @ent SET [EData]=REPLACE([EData],'{"Name":"Phone","Value":"'+[EPhone]+'"}','{"Name":"Name","Value":"'+[EName]+'"}')

select * from @ent

If you run that script it will show what your Entity data would look like if we went further and updated the [Entities] table. It is non-destructive as-is, so try it out to see if your results look ok, and we can go from there.

Here is what I think I need to achieve. In CustomData column, rename all ‘Phone’ to ‘Name’
And then swap data from phone no and Customer Name

Yes, that is what needs to be done, which is what the script does using an in-memory temporary table.

The next step would be to take the data in the temp table and use it to update records in the [Entities] table.

Then we need to update the [EntityTypes] table to change [PrimaryFieldName] to ‘Phone’.

Finally, we need to update the [EntityCustomFields] table to change the [Name] column to contain ‘Name’ or ‘Customer Name’ instead of ‘Phone’.

Ok I have no understanding of sql so i need some assistance.
I have managed to rename Phone to Name in the CustomData column.

UPDATE Entities
SET CustomData = REPLACE(CustomData, 'Phone', 'Name')
FROM [SambaPOS5].[dbo].[Entities]

I have copied alll Names to the notes column

UPDATE Entities
SET Notes = Name
FROM [SambaPOS5].[dbo].[Entities]

Im stuck trying to select the Phone no ONLY and copy it to the Name column.
Then I need to copy the names from Notes column to replace phone no. in CustomData.

Look at my query. This should help:

-- set these values as necessary
declare @phoneNumLength int = 9
declare @phoneFieldName nvarchar(100) = 'Phone'
declare @entType varchar(100) = 'Customers'

-- nothing else to set beyond here
declare @phoneFieldNameLen int = LEN(@phoneFieldName)+12


-- this part picks out the phone number
substring([customdata], charindex('"'+@phoneFieldName+'"',[CustomData])+@phoneFieldNameLen,@phoneNumLength) as i

I intentionally parameterized it using variables so that you could use your own values, since they may be different than mine (i.e. where I use ‘Phone’, you may use ‘Tel No’, and my phone numbers are 9 digits in length, while yours may be 8, or 15, or whatever.)

I have a database with no customers. If I set primary field name as Phone in software and then add the customers, will that be all right? Then can I have customers with same name and different phone numbers?

Yes. Configure a custom field for customer name and set your primary field as phone number.

1 Like