Recommended Method for Pulling a Custom Table Data in C# ?

kentico guy asked on February 14, 2020 16:43

What is the easiest/simplest/quickest method in Kentico to pull a value from a custom table?

Let's say I've got a table "My_Veggies" and I want to pull from a column called "ExpirationDate" in the context of a macro method called from the current document context. I don't really need you to write out the code; please just tell me the name of the method and I'll play around with it.

I've been looking through the documentation, but I'd like a quick pointer; if anyone has something for me, thanks!

Recent Answers


Peter Mogilnitski answered on February 14, 2020 19:33

{% GlobalObjects.CustomTables["customtable.My_Veggies"].Items.Where("ItemID = 1")[0]["ExpirationDate"]%}

1 votesVote for this answer Mark as a Correct answer

kentico guy answered on February 14, 2020 20:46 (last edited on February 14, 2020 20:46)

Is there a way to do this in C# not in a macro? Sorry my OP was confusing. I am actually invoking a macro method to call C# code and I want to run the query there.

Your answer is exactly what I'm looking for though, other than I need to call that in the app code not in the macro itself. I just checked for something similar in intellisense and I couldn't find any methods that I could port your code to.

Thanks for the help!

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on February 14, 2020 21:45

Custom Table API Examples

CustomTableItem item1 = CustomTableItemProvider.GetItems("customtable.My_Veggies")
                                                    .WhereEquals("ItemName", "SampleName")
                                                    .TopN(1)
                                                    .FirstOrDefault();

string itemTextValue = ValidationHelper.GetString(item1.GetValue("ExpirationDate"), "");
1 votesVote for this answer Mark as a Correct answer

kentico guy answered on February 14, 2020 22:33

Would this work?

var item = CustomTableItemProvider.GetItems("customtable.My_Veggies").WhereEquals("ExpirationDate", DateTime.Now);

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 16, 2020 04:12

What Peter has, except you would probably do the ValidationHelper.GetDateTime if the ExpirationDate is a date type.

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on July 31, 2020 19:00

Him working on the e-com notification and i have a custom table (customtablename) and I can't figure out how to pass the Order.ID Order.ID in the where condition:

{% GlobalObjects.CustomTables["customtablename"].Items.Where("OrderID = '" + Order.ID + "'")[0]["FirstName"]

Order.ID in the where condition doesnt work, but if i only put {% Order.ID #%} in my html notification it return the good value...

Cause someone have a solution for that ? thank you

0 votesVote for this answer Mark as a Correct answer

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