legacy-knowledge-base
公開されました Jun. 30, 2025

How to programmatically add a form entry with API?

投稿者

Sorin Pop

knowledge-article-header-disclaimer-how-to

knowledge-article-header-disclaimer

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • I am currently working with a Liferay form. I am attempting to submit a new record to this form using the /ddm.ddmforminstancerecord/add-form-instance-record API via JSON Web Services (JSONWS). This API requires a parameter named ddmFormValues, which needs to be passed as a JSON object.

    I am encountering difficulties understanding the correct structure for the ddmFormValues parameter in this context. Could you please provide guidance or an example of the proper JSON structure for submitting a record with a single selection field?

Environment

  • 7.4

Resolution

  • Theoretically, there could be 2 ways of adding a form entry programmatically (one by using the JSONWS API and one one by using the Forms headless API). As it turns out, indeed the JSONWS API is not actually working, it's not possible to use, but instead the headless one can be used.

     

     

    Possibility #1: /ddm.ddmforminstancerecord/add-form-instance-record

    The first possibility I considered was to use the /ddm.ddmforminstancerecord/add-form-instance-record JSONWS API.

    Unfortunately, however, this does not seem to be possible. The only available version of this API takes in a DDMFormValues as an argument, which does not seem to be possible to pass into JSONWS since DDMFormValues does not have a default constructor.

     

    So indeed this cannot be used for this purpose.

     

    Possibility #2: POST /v1.0/forms/{formId}/form-records Headless API

    The second possibility I considered was to use a POST request to the /v1.0/forms/{formId}/form-records headless API. 

     


    This proved to be working and we suggest to use this, even though, as side note, this Forms headless API is supposed to be deprecated. But it is still functional, it's there, and it will only be removed when the actual Forms component will be removed from the product UI as well. So you can, for now, use this headless API instead.

    However, on the long term, the ideal way to approach this would be to not use (create) Forms (in Content&Data), but rather create an object (with the same kind of fields that you need on the form) and then use that with a form container fragment to display it as a form on a page, and you can programmatically add object entries (same as "form entries") using the headless object APIs; please see below some links to some of the objects documentation that might help you get familiar with this way of approaching the matter, by using the Objects framework:

    https://learn.liferay.com/web/guest/w/dxp/liferay-development/objects


    https://learn.liferay.com/web/guest/w/dxp/liferay-development/objects/understanding-object-integrations/using-custom-object-apis

 

         https://learn.liferay.com/web/guest/w/dxp/liferay-development/objects/using-forms-with-objects

  •  

    In other words, especially if you are just starting out with Liferay and with planning your system, rather avoid using the Forms component (which is not developed anymore and will be removed sooner or later), and rather use the Objects component (and the Objects headless API).

 

 

 

did-this-article-resolve-your-issue

legacy-knowledge-base