Hi ,
I’ve created custom field which is a dropdown. So, for that I am adding the options dynamically using the below APIs
API URL'S
1. /rest/api/3/field/${fieldId}/context
2. /rest/api/3/field/${fieldId}/context/${globalContext.id}/option
The options are added successfully, but it is not project specific. The options are visible under all the projects under my account. So i need a way to apply project scope for each option I create.
Any guidance or insights from the community on how to proceed functionality it would be greatly appreciated.
I’ve attached the relevant code snippet below.
Thanks in advance for your help!
Good Morning Vitheya!
I can see in this code snipet
const globalContext = contextData.values.find(ctx => ctx.isGlobalContext);
that you chose the global context of the field, which is the reason why it shows up in all projects.
You would need to define a new context for each set of projects you want your field to have different options in.
const targetContext = contextData.values.find(ctx => ctx.name === "specific Context");
You can read more about contexts here:
https://support.atlassian.com/jira-cloud-administration/docs/configure-custom-field-context/
Hope that was helpful. Let me know if you need more help!
Regards,
Jaime Escribano
Hi Jaime,
As you Suggested I've set Specific context but still its fail, I've attached the code snippet below kindly take a look.
Code Snippet
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good morning Vitheya! Hope you enjoyed your weekend.
Before I look into this, would you share what the failure is? API Error, result is not the same as expected, some other issue?
Regards,
Jaime
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jaime,
This is error I'm getting
"Error while creating folderTypeError: Cannot read properties of undefined (reading '0')"
I've also attached UI code for your reference kindly take a look
Code snippet 1:
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;
}
if (parentFolderName === 'Test Repository') {
bodyData = {
name: data.folderName,
fieldId: testCaseFieldId,
projectKey: projectKey,
projectId: projectId
}
}
else {
console.log("else..........", projectId)
bodyData = {
name: `${data.folderName}(${parentFolderName})`,
fieldId: testCaseFieldId,
projectKey: projectKey,
projectId: projectId
}
}
try {
const response = await invoke('addOptionToCustomField', bodyData); // API call to get projects
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 [];
}
}
Code snippet 2:
resolver.define("addOptionToCustomField", async({payload}) => {
const { fieldId, name, projectKey } = payload
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();
const targetContext = contextData.values.find(ctx => ctx.name === projectKey);
const optionData = [{ value: name }];
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()
return data
}
catch(error){
return {"code": 2000, "message": "Error while creating folder"}
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Backend Code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.