Issue with "Code Name" in Form Component When Auto Pre-Fill is Enabled
We have encountered an issue with the "Code Name" field in the form component. When selecting the "Enable option to automatically pre-fill code names", the field returns the value AUTO instead of the expected generated code name.
This behaviour seems incorrect, as we expect it to generate a proper code name based on the form item. Could you please confirm if this is a known issue and suggest a possible resolution or workaround?
It happens when we create the content types pages and create fields.
Attaching some of the screenshot:
When using the "Code Name" form component
When we retrieve the headless item via Graphql
Environment
- Xperience by Kentico version: 29.6.3
Answers
I believe the Code Name is reserved for Module Classes (because it uses the generated TypeInfo to detect what the code name field is and then replaces the AUTO with an actual code name based on the Display Name field.
Content Items in the hub automatically get a code name that they generate.
Trevor is correct.
What do you expect is the source of the generated code name - a random value, transformed content item name, or some other field in the content type?
If you need to generate non-display, but readable identifiers for content items I would recommend using a global event to generate these when new content items are created. This event handler would set the "code name" field programmatically based on logic you define. If you only add a handler for the Content Item Create events then once the code name is set it won't change. Additionally, you can use the Text with label Form component for text fields of the content type. This will ensure the value cannot be modified in the administration UI but it will be visible.
You could also use the Guid
values of the content items exposed by _system {````id }
, but this value is not exposed in the administration UI by default.
If you would like the content item's internal CodeName
to be exposed over headless channels or , make a request on our roadmap explaining your use-case so we can best understand how to help solve your challenge and prioritize the work.
To answer this question, you have to login first.