{"id":3884,"date":"2023-09-21T14:07:53","date_gmt":"2023-09-21T13:07:53","guid":{"rendered":"https:\/\/help.expertsender.com\/?post_type=es&#038;p=3884"},"modified":"2024-03-19T13:25:10","modified_gmt":"2024-03-19T12:25:10","slug":"insertrow","status":"publish","type":"es","link":"https:\/\/help.expertsender.com\/pl\/emp\/dynamic-content\/data-tables\/insertrow\/","title":{"rendered":"InsertRow"},"content":{"rendered":"\n<p><code>InsertRow<\/code> method allows inserting a single row in a custom data table. This is an equivalent of SQL <code>INSERT<\/code> query.<\/p>\n\n\n\n<p>This method is useful if you need to save some particular data related to each sent email, e.g. date or GUID.<\/p>\n\n\n\n<p><strong>1. Method signature<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"InsertRow(table, columns, values)\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #82AAFF\">InsertRow<\/span><span style=\"color: #BABED8\">(table<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> columns<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> values)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Parameter definition:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Name<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>table<\/td><td>string<\/td><td>Required. Table name.<\/td><\/tr><tr><td>columns<\/td><td>array of string<\/td><td>Required. Array of column names in table we insert a record to. Submitting the list is required to handle cases where some columns are omitted (e.g. those with default values) or supplied in different order than in the table.<\/td><\/tr><tr><td>values<\/td><td>array of object<\/td><td>Required. Array of column values. Values are passed as object, so multiple types can be passed (numeric, text etc). See examples.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>2. Usage and examples<\/strong><\/p>\n\n\n\n<p>You can call <code>InsertRow<\/code> method using curly braces syntax. You may put in anywhere in the email template code since its output is empty string.<\/p>\n\n\n\n<p>Example 1 &#8211; the most simple call<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"${InsertRow('MyTable', new string[] {'MyColumn'}, new object[] {'foobar'})}\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">$<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">InsertRow<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">MyTable<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">string<\/span><span style=\"color: #F07178\">[] <\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">MyColumn<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">},<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">object<\/span><span style=\"color: #F07178\">[] <\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">foobar<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">}<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Equivalent SQL query:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO MyTable (MyColumn) VALUES ('foobar')\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">INSERT INTO <\/span><span style=\"color: #82AAFF\">MyTable<\/span><span style=\"color: #BABED8\"> (MyColumn) <\/span><span style=\"color: #82AAFF\">VALUES<\/span><span style=\"color: #BABED8\"> (<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">foobar<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This assumes we have a simple table with one column.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Example 2 &#8211; inserting a record to table with multiple columns of different types<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"${InsertRow('MyTable', new string[] {'MyIntColumn', 'MyTextColumn', 'MyDateColumn'}, new object[] {123, 'foobar', new System.DateTime(2015, 1, 26, 14, 0, 0)})}\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">$<\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #82AAFF\">InsertRow<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">MyTable<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">string<\/span><span style=\"color: #F07178\">[] <\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">MyIntColumn<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">MyTextColumn<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">MyDateColumn<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">},<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">object<\/span><span style=\"color: #F07178\">[] <\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #F78C6C\">123<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">foobar<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> new System.DateTime(<\/span><span style=\"color: #F78C6C\">2015<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #F78C6C\">1<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #F78C6C\">26<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #F78C6C\">14<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #F78C6C\">0<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #F78C6C\">0<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">}<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Equivalent SQL query:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"INSERT INTO MyTable (MyIntColumn, MyTextColumn, MyDateColumn) VALUES (123, 'foobar', '2015-01-26 14:00:00')\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">INSERT INTO <\/span><span style=\"color: #82AAFF\">MyTable<\/span><span style=\"color: #BABED8\"> (MyIntColumn<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> MyTextColumn<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> MyDateColumn) <\/span><span style=\"color: #82AAFF\">VALUES<\/span><span style=\"color: #BABED8\"> (<\/span><span style=\"color: #F78C6C\">123<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">foobar<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2015-01-26 14:00:00<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Of course, it is possible to use any of available<a href=\"https:\/\/sites.google.com\/expertsender.com\/dynamic-content-documentation\/predefined-variables\"> predefined variables<\/a>,<a href=\"https:\/\/sites.google.com\/expertsender.com\/dynamic-content-documentation\/snippets\"> snippets<\/a> or subscriber properties as inserted values.<\/p>\n","protected":false},"author":6,"featured_media":0,"parent":3874,"menu_order":215,"template":"","format":"standard","emp-category":[],"class_list":["post-3884","es","type-es","status-publish","format-standard","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es"}],"about":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/types\/es"}],"author":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/users\/6"}],"version-history":[{"count":2,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3884\/revisions"}],"predecessor-version":[{"id":8868,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3884\/revisions\/8868"}],"up":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3874"}],"wp:attachment":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/media?parent=3884"}],"wp:term":[{"taxonomy":"emp-category","embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/emp-category?post=3884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}