Hi ,
How can I set scope for a specific project? In case you haven't seen the code snippets, I've sent them again. Please take a look at them
UI Code
const onSubmit = async (data) => {
var bodyData;
setIsLoading(true)
const folderExists = tree.some(folder => folder.value === data.folderName || folder.value === `${data.folderName}(${parentFolderName})`);
if (folderExists) {
setIsLoading(false)
setFlagTitle('Failure!');
setFlagMessage('Error: Folder name already exists');
addFlag();
return;
}
console.log("ParentfoldernameID..........", projectId)
if (parentFolderName === 'Test Repository') {
console.log("ParentfoldernameID..........", projectId)
bodyData = {
name: data.folderName,
fieldId: testCaseFieldId,
projectKey: projectKey,
projectId: projectId
}
console.log("bodyDataID..........", projectId)
}
else {
console.log("else..........", projectId)
bodyData = {
name: `${data.folderName}(${parentFolderName})`,
fieldId: testCaseFieldId,
projectKey: projectKey,
projectId: projectId
}
console.log("projectid..........", projectId)
}
console.log("Data...", bodyData)
try {
const response = await invoke('addOptionToCustomField', bodyData); // API call to get projects
console.log("comp Response....", response)
if (response.options[0].id) {
setIsLoading(false)
setFlagTitle("Success!")
setFlagMessage('Folder created successfully')
setIsOpen(false)
setShowParentDrp(false);
reset();
addFlag();
setTree([])
setFolderLoader(true)
getUpdatedComponentList()
}
} catch (error) {
setIsLoading(false)
setFlagTitle('Failure!')
setFlagMessage(`Error while creating folder${error}`)
addFlag();
return [];
}
}
Backend Code
resolver.define("addOptionToCustomField", async({payload}) => {
console.log("addOptionToCustomField")
const { fieldId, name, projectKey } = payload
console.log("projectkey.........",projectKey)
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)
const targetContext = contextData.values.find(ctx => ctx.name === projectKey);
const optionData = [{ value: name }];
console.log("Option Data........", optionData)
var res = await api.asApp().requestJira(route`/rest/api/3/field/${fieldId}/context/${targetContext}/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"}
}
});