Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a Scope for Specific Project

Vitheya Monikha May 9, 2025

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.

 

resolver.define("addOptionToCustomField", async({payload}) => {

  const { fieldId, name } = payload
  try{

    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 globalContext = contextData.values.find(ctx => ctx.isGlobalContext);

    const optionData = [{ value: name }];

    var res = await api.asApp().requestJira(route`/rest/api/3/field/${fieldId}/context/${globalContext.id}/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"}
  }

});


Thanks in advance for your help!

 

1 answer

1 vote
Jaime Escribano
Contributor
May 9, 2025

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events