Avoid duplicate values in custom table in kentico one field.allow only unique values

surakshith reddy asked on December 14, 2020 10:41

Avoid duplicate values in custom table in kentico one field.allow only unique values

I have visited some articles and tried this code by adding below code in validation rules section

{%foreach (i IN GlobalObjects.CustomTables["customtable.TableName"].Items) {if (i.FieldName== FieldName.Value && i.IdentityFieldName != IdentityFieldName.Value) { return false;}}return true;%}

Some how its not working

Can any one please help me

Correct Answer

surakshith reddy answered on December 15, 2020 10:20

Hi Brenden Kehren,

Now the issue is fixed. Thank you for your quick response. Any ways I have added like below in add validation section for particular filed of table.

Ex: TT.states is my code name for table foreach (i IN GlobalObjects.CustomTables["TT.States"].Items) { if (i.StateName== StateName.Value ) { return false; } } return true;

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on December 14, 2020 19:34

Where are you placing this macro code?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.