Skip to main content

Issue Settings

In the previous step, we extracted raw issue data. Some fields contain specific IDs like Issue Sub Type and Root Cause, while Custom Attributes follow an id-value pair pattern. These are all part of the Issue Settings. To retrieve their full details, we'll need to make additional API calls to the Issues endpoints.

In addition, the APIs permissions follows the user permission setting of the logged user, who authorizes this sample to manipulate the issues. We will also add one more help function to get the user permissions.

We will append a couple of helper functions below to the end of the services/aps.js file, for fetching related issue settings.

services/aps.js
 // Issue Settings

//get issue sub types setting
service.getIssueSubtypes = async (projectId, token) => {
let allSubtypes = [];
let offset = 0;
let totalResults = 0;
do{

const resp = await issuesClient.getIssuesTypes(projectId, {accessToken:token,include:'subtypes',offset:offset});
let eachPage = resp.results.flatMap(item => item.subtypes);
allSubtypes = allSubtypes.concat(eachPage);
offset += resp.pagination.limit;
totalResults = resp.pagination.totalResults;
}while (offset < totalResults)
return allSubtypes;
};

//get issue root causes setting
service.getIssueRootcauses = async (projectId, token) => {
let allRootcauses = [];
let offset = 0;
let totalResults = 0;
do{

const resp = await issuesClient.getRootCauseCategories(projectId, {accessToken:token,include:'rootcauses',offset:offset});
let eachPage = resp.results.flatMap(item => item.rootCauses);
allRootcauses = allRootcauses.concat(eachPage);
offset += resp.pagination.limit;
totalResults = resp.pagination.totalResults;
}while (offset < totalResults)
return allRootcauses;
};

//get custom attributes definitions
service.getIssueCustomAttributesDefs = async (projectId, token) => {
let allCustomAttributesDefs = [];
let offset = 0;
let totalResults = 0;
do{

const resp = await issuesClient.getAttributeDefinitions(projectId, {accessToken:token,offset:offset});
allCustomAttributesDefs = allCustomAttributesDefs.concat( resp.results);
offset += resp.pagination.limit;
totalResults = resp.pagination.totalResults;
}while (offset < totalResults)
return allCustomAttributesDefs;
};

//get issue permissions of the user
service.getIssueUserProfile= async (projectId, token) => {

const resp = await issuesClient.getUserProfile(projectId, {accessToken:token});
return resp
};
info

Issue Sub Type is a child of Issue Type . This sample iterates each type, extracts its sub types to build the collection. Similarly, Issue Root Cause is a child of Issue Root Cause Caregory. This sample iterates each category , extracts its root causes to build the collection. The corresponding APIs also return types or categories in pagination.

No API yet to get Issues Permission table like ACC UI does. Current API supports to fetch the logged user permission only.

Server endpoints

Next, let's expose the routes to retrieve issue settings to the client-side code through another set of endpoints.

We will start by importing the issue settings helper functions defined in services/aps.js file. Add the following content to routes/issues.js file.

routes/issues.js
const { authRefreshMiddleware,
getIssues,
createOrModifyIssues
getIssueSubtypes,
getIssueRootcauses,
getIssueCustomAttributesDefs,
getIssueUserProfile
} = require('../services/aps.js');

router.get('/api/issues/subtypes', async function(req, res, next){
try {
const subTypes = await getIssueSubtypes(req.query.projectId,req.internalOAuthToken.access_token);
res.json(subTypes);
} catch (err) {
next(err);
}
});

router.get('/api/issues/rootcauses', async function(req, res, next){
try {
const rootcauses = await getIssueRootcauses(req.query.projectId,req.internalOAuthToken.access_token);
res.json(rootcauses);
} catch (err) {
next(err);
}
});

router.get('/api/issues/customAttDefs', async function(req, res, next){
try {
const customAttributes = await getIssueCustomAttributesDefs(req.query.projectId,req.internalOAuthToken.access_token);
res.json(customAttributes);
} catch (err) {
next(err);
}
});


router.get('/api/issues/issueUserProfile', async function(req, res, next){
try {
const issueUserProfile = await getIssueUserProfile(req.query.projectId,req.internalOAuthToken.access_token);
res.json([issueUserProfile]);
} catch (err) {
next(err);
}
});

Try it out

And that's it for the server side. Time to try it out!

Issues Response