Hi,
The project ID is not available in the context data. I would like to know how to add my project ID to it. I have also added the context data JSON as below.
Could you please let me know how to add projectID to the context data JSON?
This is the backend code
resolver.define("addOptionToCustomField", async ({ payload }) => {
console.log("addOptionToCustomField")
const { fieldId, name, projectId } = payload
console.log("projectkey.........", projectId)
try {
console.log("Payload to create options...", fieldId)
const contextResponse = await api.asApp().requestJira(route`/rest/api/3/field/${fieldId}/context`, {
method: "GET",
headers: { "Accept": "application/json" },
});
const contextData = await contextResponse.json();
console.log("contextData......", contextData)
console.log("payload.projectId.........", projectId)
const targetContext = contextData.values.find(ctx =>
ctx.projectIds && ctx.projectIds.includes(projectId)
);
console.log("targetContext........", targetContext)
const optionData = [{ value: name }];
console.log("Option Data........", optionData)
var res = await api.asApp().requestJira(route`/rest/api/3/field/${fieldId}/context/${targetContext.id}/option`, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ options: optionData }),
});
const data = await res.json()
console.log(`✅ Dropdown options added for ${fieldId}!...`, data);
return data
}
catch (error) {
return { "code": 2000, "message": "Error while creating folder" }
}
});
JSON
contextData...... {
maxResults: 50,
startAt: 0,
total: 1,
isLast: true,
values: [
{
id: '12823',
name: 'Default Configuration Scheme for Folders',
description: 'Default configuration scheme generated by Jira',
isGlobalContext: true,
isAnyIssueType: true
}
]
}