ICT:Automatic IDs: Difference between revisions
Created page with "{{#set:Description=Documentation for generating and querying automatic IDs using Page Forms and Cargo.}} = Automatic ID Generation for Cargo Tables = This page documents the workflow for generating automatic, composite IDs using the Page Forms and Cargo extensions. == Overview == While Page Forms does not have a "native" ID generator button, unique IDs can be constructed by: # Combining user-input attributes in the storage..." |
No edit summary |
||
| Line 12: | Line 12: | ||
== 1. Template Logic (The "Store" Method) == | == 1. Template Logic (The "Store" Method) == | ||
To create an ID from a combination of attributes, logic is placed inside the | To create an ID from a combination of attributes, logic is placed inside the <nowiki>{{#cargo_store}}</nowiki> function. | ||
=== Example Cargo Declaration === | === Example Cargo Declaration === | ||
Define your table in your Schema template: | Define your table in your Schema template: | ||
<pre> | <pre> | ||
<nowiki> | |||
{{#cargo_declare: | {{#cargo_declare: | ||
_table = Projects | _table = Projects | ||
| Line 23: | Line 24: | ||
|Year = Integer | |Year = Integer | ||
}} | }} | ||
</nowiki> | |||
</pre> | </pre> | ||
| Line 28: | Line 30: | ||
In your data template, concatenate the fields to create the `ProjectID`: | In your data template, concatenate the fields to create the `ProjectID`: | ||
<pre> | <pre> | ||
<nowiki> | |||
<includeonly> | <includeonly> | ||
{{#cargo_store: | {{#cargo_store: | ||
_table = Projects | _table = Projects | ||
|ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}} | |ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}} | ||
|Category = {{{Category|}}} | |Category = {{{Category|}}} | ||
|Year = {{{Year|}}} | |Year = {{{Year|}}} | ||
}} | }} | ||
</includeonly> | </includeonly> | ||
</nowiki> | |||
</pre> | </pre> | ||
| Line 42: | Line 46: | ||
=== Page Name Formula === | === Page Name Formula === | ||
In the | In the <nowiki>{{{info}}}</nowiki> tag, define how the page is named automatically: | ||
< | <pre> | ||
<nowiki> | |||
{{{info|page name=<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}} | {{{info|page name=<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}} | ||
</ | </nowiki> | ||
</pre> | |||
=== Field Validation === | === Field Validation === | ||
Force the form to check if an ID already exists: | Force the form to check if an ID already exists: | ||
< | <pre> | ||
<nowiki> | |||
{{{field|ProjectID|unique|input type=text|hidden}}} | {{{field|ProjectID|unique|input type=text|hidden}}} | ||
</ | </nowiki> | ||
</pre> | |||
== 3. Querying Records == | == 3. Querying Records == | ||
To retrieve data using your custom ID, use the | To retrieve data using your custom ID, use the <nowiki>{{#cargo_query:...}}</nowiki> parser function. | ||
=== Filter by Composite ID === | === Filter by Composite ID === | ||
< | <pre> | ||
<nowiki> | |||
{{#cargo_query: | {{#cargo_query: | ||
|tables = Projects | |tables = Projects | ||
| Line 64: | Line 73: | ||
|format = table | |format = table | ||
}} | }} | ||
</ | </nowiki> | ||
</pre> | |||
</ | |||
== Extensions Used == | == Extensions Used == | ||
Revision as of 08:55, 28 January 2026
{{#set:Description=Documentation for generating and querying automatic IDs using Page Forms and Cargo.}}
Automatic ID Generation for Cargo Tables
This page documents the workflow for generating automatic, composite IDs using the Page Forms and Cargo extensions.
Overview
While Page Forms does not have a "native" ID generator button, unique IDs can be constructed by:
- Combining user-input attributes in the storage template.
- Using the form's page name formula to ensure uniqueness.
- Enforcing uniqueness via form validation.
1. Template Logic (The "Store" Method)
To create an ID from a combination of attributes, logic is placed inside the {{#cargo_store}} function.
Example Cargo Declaration
Define your table in your Schema template:
{{#cargo_declare:
_table = Projects
|ProjectID = String
|Category = String
|Year = Integer
}}
Example Cargo Store
In your data template, concatenate the fields to create the `ProjectID`:
<includeonly>
{{#cargo_store:
_table = Projects
|ProjectID = {{{Category|}}}-{{{Year|}}}-{{#time:U}}
|Category = {{{Category|}}}
|Year = {{{Year|}}}
}}
</includeonly>
2. Form Definition
To ensure the user doesn't create a duplicate ID, use the `unique` and `page name` parameters in Page Forms.
Page Name Formula
In the {{{info}}} tag, define how the page is named automatically:
{{{info|page name=<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}
Field Validation
Force the form to check if an ID already exists:
{{{field|ProjectID|unique|input type=text|hidden}}}
3. Querying Records
To retrieve data using your custom ID, use the {{#cargo_query:...}} parser function.
Filter by Composite ID
{{#cargo_query:
|tables = Projects
|fields = _pageName=Page, Category, Year
|where = ProjectID = 'Hardware-2024-171523421'
|format = table
}}
Extensions Used
- Page Forms: Handles the user interface and page naming.
- Cargo: Handles data storage and querying.
- ParserFunctions: Used for string manipulation and date formatting.