Change Form visibility using Automation and API

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 a workaround to the feature request "Forms Automation: Automation to control the forms visibility", this article is meant to help users who want to use the new experimental features of the Forms API to automatically change the form visibility between internal and external.

 

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 "Change visibility to external" or "Change visibility to internal" in a Put web request. For example:
      • To change the form visibility to external when an issue is transitioned:

        - The web method will be a PUT:

        PUT /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{formId}/action/external

        - 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}}

        - The formId will be in the universally unique identifier "uuid" format. To get it you can use the Forms properties structure below:

        https://<yourCloudURL>.atlassian.net/rest/api/2/issue/<issueId>/properties/proforma.forms

        Screenshot 2023-05-22 at 17.48.05.png

        - To add the formId dynamically, you can use the smart value below:

        {{issue.properties."proforma.forms".forms.uuid}}

        - The automation rule will be as shown in the screenshot below:Screenshot 2023-06-09 at 16.52.20.png

      • To change the form visibility to internal when an issue is transitioned:

        - The web method will be a PUT:

        PUT /jira/forms/cloud/{cloudId}/issue/{issueIdOrKey}/form/{formId}/action/internal

        - The steps will be the same as above and the automation rule will be as shown in the screenshot below:Screenshot 2023-06-09 at 16.59.28.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

Kalin U
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.
June 9, 2023

Very detailed and well written step-by-step tutorial, @Bruno Altenhofen Thanks for sharing! Recently I created an automation very similar to the one you have suggested, though with a twist.

I wanted to select and attach a form to a service ticket depending on a field selected by a customer. As the number of customers and field cases is large, I used the action "Create a lookup table" so that the table can hold the form template IDs (up to 20 key-value pairs). The custom field values are the keys, whereas the template IDs are the values in our lookup table.

When the custom field value matches a form template ID, the rule executes two "Send web request" actions one after the other:

1. attach a form to the Jira issue: POST request https://api.atlassian.com/jira/forms/cloud/<cloud ID>/issue/{{issue.key}}/form

{
"formTemplate": {
"id": "{{<uuid of the form>}}"
}
}

One needs to select the option in the action "Delay execution of subsequent rule actions until we've received a response for this web request" so that the next action can process the form instance ID (not the UUID of the form template).

2. change the visibility of the newly attached form: PUT request https://api.atlassian.com/jira/forms/cloud/<cloud ID>/issue/{{issue.key}}/form/{{webResponse.body.id}}/action/external

Without the second action, the form's visibility is set to internal by default, thus not visible to the customer in the portal.

Maybe the Forms API team can consider adding parameters to the "Add form" method by allowing setting the visibility in a single call. @Simon Herd 


(i) <value> - without the brackets <, >

(i) By the way, one doesn't need the header Accept:application/json for a successful request.

Like Bruno Altenhofen likes this
Bruno Altenhofen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 4, 2023

Hey @Kalin U 

Thanks for sharing your feedback and bringing your use case to us!

Apologies for my delay in responding to you (I was a little off in the Atlassian Community these last few days). So this is a great idea and thanks for sharing it with us. We’re always keen to seek feedback on the Forms API functionality and how it meets our client's needs and/or how it could be modified to meet our customer's needs.

I'll share your example internally with the Forms dev team.

Thanks!

Like Kalin U likes this
Ralph Gerald Varon August 16, 2023

Is it possible to get a specific UUID of the form, if there are already multiple forms attached?

What if I only want one form to be internal/external1.png

Like Bruno Altenhofen likes this
Bruno Altenhofen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 20, 2023

Hey @Ralph Gerald Varon 

Is it possible to get a specific UUID of the form, if there are already multiple forms attached?

Yes, using the smart values below:

{{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

 

For more information, allow me to share with you this article that explains how to manipulate multiple forms separately:

Thanks!

Ralph Gerald Varon December 4, 2023

Amazing! thank you!

Like Bruno Altenhofen likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events