Dynamic Single Select Attribute
This 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 consisting of objects that represents the values of this attribute. "id" and "name" properties are mandatory for each object. Also, objects contains "description", "defaultValue", "order", "fontClass", "enabled". Following parameters are also passed to this web service; issueId, issueKey, username, userKey, projectId, projectKey, issueTypeId. Which parameter will be added to the URL is determined by selecting parameters from the extra parameter section in the single select rest api attribute create dialog. If no parameter is selected, the array containing all attribute values is returned.
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;
};