API Questions on Kentico API.
Version 5.x > API > Get SiteID for insert query View modes: 
User avatar
Member
Member
mj-y - 12/18/2012 11:24:52 PM
   
Get SiteID for insert query
I have a custom table with an insert query, and I have a SiteID column in my table ... I want to fill it automatically through my sql query ... Is it possible? If not how should I fill this column during insert?
note: I use Kentico5.5R2

User avatar
Kentico Support
Kentico Support
kentico_janh - 12/19/2012 3:18:35 AM
   
RE:Get SiteID for insert query
Hello,

Yes, you can update the Insert query and set the siteid manually, so instead of:

INSERT INTO customtable_displayname ([ItemCreatedBy], [ItemCreatedWhen], [ItemModifiedBy], [ItemModifiedWhen], [ItemOrder], [ItemGUID], [displayname], [siteid] ) VALUES ( @ItemCreatedBy, @ItemCreatedWhen, @ItemModifiedBy, @ItemModifiedWhen, @ItemOrder, @ItemGUID, @displayname, @siteid); SELECT SCOPE_IDENTITY() AS [ItemID] 


you will have:

INSERT INTO customtable_displayname ([ItemCreatedBy], [ItemCreatedWhen], [ItemModifiedBy], [ItemModifiedWhen], [ItemOrder], [ItemGUID], [displayname], [siteid] ) VALUES ( @ItemCreatedBy, @ItemCreatedWhen, @ItemModifiedBy, @ItemModifiedWhen, @ItemOrder, @ItemGUID, @displayname, 1); SELECT SCOPE_IDENTITY() AS [ItemID] 


Best regards,
Jan Hermann

User avatar
Member
Member
mj-y - 12/19/2012 5:05:09 AM
   
RE:Get SiteID for insert query
I dont want to give it an static number ... I want to get current site id and use it ... like orders table in eccomerce!

User avatar
Kentico Support
Kentico Support
kentico_janh - 12/19/2012 5:15:35 AM
   
RE:Get SiteID for insert query
Hello,

Then you need to use macros instead. Please set the Attribute default value for that field to {%currentsite.siteid%} and set the Display attribute in the editing form to false.

Best regards,
Jan Hermann

User avatar
Member
Member
mj-y - 12/19/2012 5:29:50 AM
   
RE:Get SiteID for insert query
thx so much :d that worked ...
where can I find the list of macros that can be used here?

User avatar
Kentico Support
Kentico Support
kentico_janh - 12/19/2012 5:38:27 AM
   
RE:Get SiteID for insert query
Hello,

You are welcome. You can practically use any context macro which is listed in our macro editor. To find out how to open a macro editor please read the Entering macros section from following documentation:

Macros

Best regards,
Jan Hermann