Kentico Custom Table

Dominic Carvalho asked on January 15, 2019 15:09

Hey

Is their a method that will allow me to check whether a value exists in my custom table ? I have a column called CountryAlias and would like to check that if a certain country code exists in the table.

This is what I am trying:

 {%if(GlobalObjects.CustomTables["customtable.DomTest"].Items.ItemsAsFields.CountryAlias.Exists("CA")) {%}
      <p>True</p>
    {%} else{ %}
        <p>False</p>
    {%}%}

It doesn't seem like the .Exists is working, I just want to check if "CA" exists in the table and if it does return true otherwise false.

Kind Regards Dominic Carvalho

Correct Answer

Dragoljub Ilic answered on January 15, 2019 16:58

Hi,

You can use InList to check if value is in the list of other values: "CA".InList(GlobalObjects.CustomTables["customtable.DomTest"].Items.ItemsAsFields.CountryAlias)

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on January 15, 2019 15:55 (last edited on December 10, 2019 02:31)

If can you explain what your final goal is? You can do it with a loop or transformation:

{%
foreach (item in  GlobalObjects.CustomTables["customtable.DomTest"].Items) {
    If (item["CountryAlias"] == 'CA') { "<p>True</p>" } else { "<p>false</p>" }
}
|(identity)GlobalAdministrator%}    
0 votesVote for this answer Mark as a Correct answer

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