Symptoms
Is there a simple way to mark a column in an editable list view as unique such that the editable list view cannot be saved if there are any duplicates in the identified column?
Diagnoses
For a Smartbox type Smartobject, there is a "Unique" Smartobject Property attribute that may accomplish what you are attempting with the editable list. If the same value exists when attempting to create a new item or update an existing item the following error will be thrown and the record will not be created/saved:
Unable to insert a duplicate value into this property. The value 'value' already exists in property 'PropertyName'.
Resolution
If you are using a SQL Server type Smartobject instead, you may be able to achieve the same functionality using a stored proc to achieve this unique save/unique create method.
Sample sproc:
USE SDBName]
GO
/****** Object: StoredProcedure rdbo].oUniqueSave] Script Date: 10/26/2015 9:55:44 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE Rdbo].oUniqueSave]
-- Add the parameters for the stored procedure here
@id int,
@TextField1 nvarchar(max),
@IntField1 int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
BEGIN TRY
IF NOT EXISTS (SELECT TextField1 FROM dbo.Table_1 WHERE TextField1 = @TextField1)
AND NOT EXISTS (SELECT IntField1 FROM dbo.Table_1 WHERE IntField1 = @IntField1)
UPDATE dbo.Table_1
SET TextField1 = @TextField1, IntField1 = @IntField1
WHERE ID = @id
ELSE
THROW 50000, 'My Custom Error: Record already exists', 1
END TRY
BEGIN CATCH
THROW
END CATCH
END
** The stored proc example provided has not been thoroughly tested and may not be optimally built, but does seem to achieve the uniqueness check on save/update.