{"id":1116,"date":"2008-02-29T03:45:01","date_gmt":"2008-02-29T09:45:01","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/docs\/?page_id=1116"},"modified":"2024-11-22T16:43:49","modified_gmt":"2024-11-22T22:43:49","slug":"auto-sequencing-within-a-maintenance-application","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/auto-sequencing-within-a-maintenance-application","title":{"rendered":"Auto-Incrementing within a Maintenance Application"},"content":{"rendered":"\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><em>Click <a rel=\"noreferrer noopener\" href=\"https:\/\/www.mrc-productivity.com\/legacy\/maint\/auto-sequencing-within-a-maintenance-application\" target=\"_blank\">here<\/a> to access the legacy version of this documentation.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>There will be many times when, on any data entry screen, you will want your numeric key field to automatically query the database to see what the last number being used was and increase that by one.<\/p>\n\n\n\n<p>In m-Power, there are two ways to accommodate this scenario, depending on your data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If your table is not automatically incrementing the key value when a new record is inserted, you may use <strong><a href=\"#auto-incrementing-via-m-power\" data-type=\"internal\" data-id=\"#auto-incrementing-via-m-power\">m-Power&#8217;s Auto Sequence feature<\/a><\/strong> to automatically populate the next available key value. <\/li>\n\n\n\n<li>If your table is set up to automatically increment the key value when a new record is inserted (i.e. your key is set up as an auto increment field on the database) then you will need to use the <strong><a href=\"#auto-incrementing-via-the-database\">Identity option from Field Settings<\/a><\/strong>.<\/li>\n<\/ul>\n\n\n\n<p>In the documentation below, both methods will be demonstrated.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Auto-Incrementing via m-Power<\/h2>\n\n\n\n<p>For developers who are working with a database table where the key value will not automatically increment for new records, you may use m-Power&#8217;s Auto Sequence option to automatically get the next available key value whenever a user adds a new record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation<\/h3>\n\n\n\n<p>In our case we will create an order entry application and select the appropriate fields from the orders table; Order #, Customer #, Order Date, Ship Date, and Order Amount.<\/p>\n\n\n\n<p>Now that our fields are selected go to &#8220;Dimensions&#8221;. When selecting Order # as a dimension, be sure to click the &#8220;Auto Sequence&#8221; check mark. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/autosequence1.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 1: Setting up a dimension field with the &#8220;Auto Sequence&#8221; option.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">Since this field will be written to the database, the &#8220;Field Type&#8221; must be set to &#8220;Update&#8221; in Field Settings. In addition, this field must be a numeric sequence key to utilize the auto-sequence functionality.<\/p>\n\n\n\n<p>Build\/Compile your application. At run time, we are shown this screen:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/images\/autosequence2.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 2: A maintainer form that loads the next available Order Number value.<\/figcaption><\/figure>\n\n\n\n<p>Notice at the top of the form, the next available order number is already populated. This tells us that the last record in the table had an order number of 301623, so our application received the next one available, 301624.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Hiding Your Auto Sequence Field<\/h3>\n\n\n\n<p>Once an auto sequence field has been set up, it is often beneficial to hide this auto sequenced field from the form. By hiding it, this prevents the user from modifying the value when adding a new record.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>The steps below will explain how to hide the row.<\/p>\n\n\n\n<div class=\"wp-block-ht-blocks-list heroic-styled-list\" id=\"heroic-styled-list-264a107a-347d-4d19-ad5b-602fc283af02\"><ol class=\"fa-ul\"><li>Open m-Painter for your application. Make sure you are editing your maintainer form page.<\/li><li>Select the &#8220;Form Group&#8221;, or whatever element that encompasses the input field you are looking to hide.<\/li><li>Press &#8220;Hide Element&#8221; from the Configure Selected Element panel (right side of the screen).<\/li><li>Save m-Painter.<\/li><\/ol><style>#heroic-styled-list-264a107a-347d-4d19-ad5b-602fc283af02 li:before{\n\t\t                   background:#000000;\n\t\t                   border-radius: 0;\n\t\t                   }<\/style><\/div>\n<\/div><\/div>\n\n\n\n<p>The following image provides a visual of which options to click inside m-Painter:<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;69e1464654992&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"69e1464654992\" class=\"wp-block-image size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"\/docs\/images\/autosequence3.jpg\" alt=\"\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Figure 3: Hiding a maintainer form field from m-Painter.<\/figcaption><\/figure>\n\n\n\n<p>In m-Painter, whenever the &#8220;Hide Element&#8221; option is used, the element will NOT be hidden from the editor, but will correctly be hidden at runtime, as shown below.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;69e1464654b88&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"69e1464654b88\" class=\"wp-block-image wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"\/docs\/images\/autosequence4.jpg\" alt=\"\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Figure 4: The Order Number input has been appropriately hidden from the form.<\/figcaption><\/figure>\n\n\n\n<p>While we cannot see the Auto Sequenced number, it is still within the HTML and ready to be submitted to the database as soon as the user clicks the &#8220;Accept&#8221; button.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Auto-Incrementing via the database<\/h2>\n\n\n\n<p>For developers who are working with a table where the key value <strong>will<\/strong> be automatically assigned by the database when a new record is inserted, you will not use m-Power&#8217;s Auto Sequence feature. <\/p>\n\n\n\n<p>While you will still select this field as your Dimension, you will need to also appropriately identify this field as an &#8220;Identity&#8221; column within the application. This will ensure m-Power does not send a value for this field, but instead allow your database to be responsible for assigning this value. <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">This document will not discuss how to create an auto generated column on a database table, but rather instruct how to set up a maintainer to accommodate an existing auto generated column. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation<\/h3>\n\n\n\n<p>Select the appropriate tables and fields as usual. In my case I will use my sales territory table and select TerritoryID, Name, Country Region Code, and Group. TerritoryID is an auto generated column in the database. To inform m-Power of this, you will navigate to Field Settings and set the Display option for that field to &#8220;Identity&#8221;:<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;69e146465500c&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"69e146465500c\" class=\"wp-block-image size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"\/docs\/images\/autosequence5.jpg\" alt=\"\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Figure 5: Marking a field as an Identity column in Field Settings<\/figcaption><\/figure>\n\n\n\n<p>That field will be selected as the Dimension field for this application as well:<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;69e14646551fc&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"69e14646551fc\" class=\"wp-block-image size-large is-resized wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"\/docs\/images\/autosequence6.jpg\" alt=\"\" style=\"width:668px;height:269px\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Figure 6: Selecting a Dimension field. Notice the Auto Sequence box is NOT checked.<\/figcaption><\/figure>\n\n\n\n<p>Build\/compile your application. At runtime, the form will show the field name but no input box or value will be present on the page, as the value is only assigned by the database once the form is submitted.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;69e14646553b4&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"69e14646553b4\" class=\"wp-block-image size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"\/docs\/images\/autosequence7.jpg\" alt=\"\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Figure 7: A maintainer form with an identity field, TerritoryID.<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Overview There will be many times when, on any data entry screen, you will want your numeric key field to automatically query the database to see what the last number being used was and increase that by one. In m-Power, there are two ways to accommodate this scenario, depending on&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[252],"ht-kb-tag":[303,302,292],"class_list":["post-1116","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-maintainer","ht_kb_tag-form","ht_kb_tag-increment","ht_kb_tag-maintainer"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":42,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1116\/revisions"}],"predecessor-version":[{"id":14402,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1116\/revisions\/14402"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=1116"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}