Automatically update Form fields answers and manipulate more than one form on an issue

 Deprecation Notice: Removing access to Forms data using Jira entity properties API

To access forms properties after the deprecation, it will be necessary to use the new feature for Forms smart-values:

Alternatively, you can access these properties via the Jira Forms REST API.



The ability to access Forms data using the Jira entity properties API has been deprecated. This feature will be removed in future versions.

Work has already started on the new Forms API functionality and we now have some experimental APIs available for use. So now Marketplace Partners can already integrate forms into their products.

For more information, please refer to the features below:

 

As an extra option of workaround to the feature request "Forms Automation: Access form fields with smart values (smartvalues)", this article is meant to help users who want to access the form field and update them with other values automatically, as well as manage with more than one form in a ticket. This can be achieved using the new experimental feature of Forms API to save form answers to different forms.

 

Workaround steps:

Create an Automation rule:

  • First, it will be needed to create an API token for the Web Request process. The Web Request needs your credentials and an API token encoded with base64.  For more information about this procedure, please refer to the documentation below:
    -    - Automation for Jira - Send web request using Jira REST API

  • We need to use the new API functionality of "Get form index" in a Get web request to get all forms on the issue. For example:
    • Getting all forms on an issue:

      - The web method will be a Get:

      Get /jira/forms/cloud/{cloudId}/issue//issue/{issueIdOrKey}/form

      - The cloudId will be your Cloud ID and not your Org ID. The easy way to get the cloud id is to go to https://<instance>.atlassian.net/admin/jira-service-desk/portal-only-customers. You will get the Cloud id in the URL (e.g.: https://admin.atlassian.com/s/<cloud_id>/jira-service-desk/portal-only-customers)

      - The issue ID or issue Key that you are using. To add the issueId or issueKey dynamically, you can use the smart value {{issue.id}} or {{issue.key}}

      - Using the log action with the smart value below to get the web response body and the reference IDs of which form:

      {{webResponse.body}} - get the body

      {{webResponse.body.id}} - get the ids

      {{webResponse.body.id.get(0)}} - get the first id

      {{webResponse.body.id.get(1)}} - get the second id

      {{webResponse.body.id.get(2)}} - get the third id
      Screenshot 2023-09-19 at 18.17.58.png
  • We need to use the new API functionality of "Get form" in a Get web request to get a single form on the issue and after use the "Save form answers" in a Put web request to populate the form fields. For example: 
    • Using Advanced branching to manipulate which form you want to manage:
      - For the first form I used the Variable name "firstForm":
      Screenshot 2023-09-19 at 18.44.02.png
    • Use the "Get form" web request to get the first form:
      Get /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{formId}
      - The formId will be in the id of the form and not the formTemplate id (for more information about it, please check this article). And, in order to dynamically get the first form it will be necessary to use the smart value {{webResponse.body.id.get(0)}} instead of the {formId}:
      Get /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{{webResponse.body.id.get(0)}}
    • Use the "Save form answers" web request to update a form field:
      Put /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{formId}
      - To get the first form it will be necessary to use the smart value {{webResponse.body.id}} instead of {formId}:
      Put /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{{webResponse.body.id}}

       Note:
      The Form fields do not support those Jira field operations such as add , remove and set .
      Therefore, to the custom data body, it will be necessary to just simply set the field value. For example, if it’s a text field, use text; if it’s a richtext paragraph, use adf; if it’s a dropdown, use choices. In this example, I used a text field and a dropdown field:
      Screenshot 2023-09-19 at 19.34.39.png
      {
      "answers": {
      "1": {
      "text": "field update by automation/API 1"
      },
      "2": {
      "choices": ["2"]
      }
      }
      }
      For more information about how access the form structure to get a field ID, please refer to the article "Reading a Forms(ProForma) field value without the JSON tab"
  • This process will be the same for the second and third forms (or for as many other forms you have): 
    • Second form:
      Screenshot 2023-09-19 at 19.30.55.png
    • Third form:
      Screenshot 2023-09-19 at 19.32.48.png

 Note: To call experimental methods the "X-ExperimentalApi" and "opt-in" header must be provided on the web request headers.

This workaround will work as shown in the screen recording below:

5 comments

Mauricio Heberle
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2023

Thanks! It helped me to send form values to Description field using this article :) 

Bin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2024

Just what I need.  Thanks!

Matthew Challenger
Contributor
July 17, 2024

Took a couple hours to piece together, but works like a charm.

The one difference for me is I don't see that 'Entity Properties' tab. Not sure why.

But to help understand what IDs to use in the "Custom Data" of the request body of the 'Save form answers' API call, I recommend that earlier in your log you output {{issue.properties."proforma.forms.i1".state.answers}} (mentioned in this article) to better understand which ID and datatype you're trying to manipulate.

Ricardo.Gomes
Contributor
August 5, 2024

How do I read the values from the form (the answers per se) using this process?

I understand this is updating the form, but all I want to do is read the answers on the form, then with those values to create subtasks to the ticket.

Can someone kindly provide me with the steps?

I was able to make the first GET request and get the webResponse.body, webResponse.body.id, and webResponse.body.id.get(0), but I'm not sure how to use them to extract the answers (there's only one single form attached to my issue).

Thank you in advance!

Like Pavan Guniganti likes this
Julian Governale
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2024

For those seeing this and looking to update a rich text field (adf) in the form which includes new line returns or bullets, I initially got the following error

{"errors":[{"status":400,"code":"BAD_REQUEST","title":"Bad request","detail":"Invalid Json: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: (org.apache.pekko.util.ByteIterator$ByteArrayIterator$$anon$1); line: 13, column: 57]"}]}

To fix this for us, i needed to use the jsonEncode function

{{issue.FieldName.jsonEncode}} 

Full Custom Data Body

{
"answers": {
"formFieldId": {
"adf": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "{{issue.FieldName.jsonEncode}}"
}
]
}
]
}
}
}
}

  

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events