Field Code Naming
In kintone, various fields can be created in an app, and each field needs to be assigned a field name and a field code.
The field name is mainly visible to users, while the field code is primarily used by app administrators and referenced in JavaScript.
This article introduces field code naming conventions and tips for using field codes in JavaScript.
Summary of This Article
- JavaScript allows variable names in Japanese, so it’s okay to use Japanese.
- It’s important to set rules as a team.
- Basically, it should match the field name.
There Is No Right Answer
There are no specific guidelines for naming conventions in kintone.
JavaScript does not restrict defining variable names in Japanese.
From these two points, there is no definitive right answer for naming.
It’s best to do what works for you. After all, it won’t cause errors.
Consistency Is Key
While there is no right answer, there are some clear wrong answers.
One of them is when team members do not follow a unified naming convention during development.
- Use the English equivalent of the field name.
- Use the same Japanese as the field name.
- Combine a unique key with the name.
In any case, it’s important to share and unify the naming rules.
Matching the Field Name Is Best
This is my personal opinion based on the rules I follow, but for example, if the field name is “Customer Name,” the field code should also be “Customer Name.”
There are several reasons for this:
- Many samples on the developer network use this rule.
- It’s easier to verify the field code corresponding to the field name.
- Even non-coders may need to manage field codes.
Things to Be Careful About in JavaScript
As mentioned earlier, JavaScript does not restrict using Japanese for variable names. However, there are a few things I pay attention to when using field codes in code. Here are some points to note.
How to Chain Properties
When retrieving field data from a record object, I do it as follows:
const { record } = kintone.app.record.get();
// OK: Write like this
record['Code1'].value;
// NG: Do not write like this
record.Code1.value;
Many people on the developer network use this writing style, so I follow it.
Avoid Destructuring Assignment
By using destructuring assignment, you can assign each field code to variables as follows, but I avoid doing this.
const { record } = kintone.app.record.get();
// NG: Avoid making Japanese directly into variables
const { Code1, Code2 } = record;
if (Code1.value === 'Field Data') {
console.log(Code1.value);
} else {
console.log(Code2.value);
}
// N/A: A bit awkward
const { Code1: code1, Code2: code2 } = record;
// OK: Write it straightforwardly
const code1 = record['Code1'];
const code2 = record['Code2'];
While having Japanese properties under the record object is barely acceptable, having Japanese variables directly as objects feels awkward, so I avoid it.
Since it’s not grammatically incorrect, those who find this clearer can use it actively.
In Conclusion
I introduced my thoughts on field code naming conventions in kintone.
Regardless of the method you adopt, it’s important to set and unify rules as a team.
I hope you found some useful information regarding naming or technical aspects of JavaScript.
Thank you for reading until the end.