Dynamic Single Select Attribute

Dynamic Single Select Attribute

“Dynamic Single Select Attribute” retrieves option values by invoking a remote web service provided by the customer an it is created by selecting “Single Select (REST API)“ attribute type.

Provided REST API should return an array of objects and each object represent a possible alternative value. Each object should have "id", "name", "enabled" as minimum. Also, each object may "description", "defaultValue", "order", "fontClass". If enabled status of an option depends on issue, project or current user, you can also pass the following parameters this web service; issueId, issueKey, username, userKey, projectId, projectKey, issueTypeId. You have to determine which parameter will be added to the URL by selecting parameters from the extra parameter section in the single select rest api attribute create dialog.

If no parameter is passed, you should return every possible option. Otherwise you may not view value of the option on timesheet view. If you need to deprecate a value, you should still return it but set its enabled property to “false”.

As seen in the example below, "issueKey=$issueKey&issueId=$issueId" needs to be selected in the extra parameters section so that attribute with id=3("name": "Lego 42009") do not appear as attribute value when adding a work log to an issue of the ERP project. This option allows the parameter to be added to the Url as “http://myrest-api/dynamic-select?issueKey=ERP-1” and the returned array does not contain the object representing this attribute value.

Similarly, if "username=$username&userKey=$userKey" is selected, the attribute value specified as id=35 ("name":"Lego 42082") will not appear as attribute option to admin user and the retured array doesn't include the object that represents this attribute.

const all = [ { "id": 3, "name": "Lego 42009", "description": "Motorized Crane (Yellow)", "defaultValue": false, "order": 1, "fontClass": "", "enabled": true }, { "id": 35, "name": "Lego 42082", "description": "Motorized Rough Terrain Crane (Red)", "defaultValue": true, "order": 2, "fontClass": "", "enabled": true }, { "id": 36, "name": "Lego 8053", "description": "Mobile Crane (Yellow)", "defaultValue": false, "order": 3, "fontClass": "fa-eye", "enabled": true } ]; exports.handler = async (event) => { console.log("event", event); let result = all.slice(); const issueKey = event.queryStringParameters ? event.queryStringParameters.issueKey : ""; const username = event.queryStringParameters ? event.queryStringParameters.username : ""; if (issueKey && issueKey.indexOf("ERP") === 0) { result = result.filter(a => a.id !== 3); } if (username == "admin") { result = result.filter(a => a.id !== 35); } console.log("response", result); const response = { statusCode: 200, body: JSON.stringify(result), }; return response; };
Adding two parameters to URL
Returned array of REST API with two parameters
All options are returned if any parameter is not selected