Forums

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

How to set the Project ID in existing JSON data

Vitheya Monikha June 18, 2025

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
}
]
}

1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
June 18, 2025

Hi @Vitheya Monikha 

The reason you're not getting projectId in the context data is because the context is global (isGlobalContext: true). It is not bound to any specific project, so projectId is not present.

To get projectId included in the context data, you need to create a custom field context scoped to a specific project rather than a global one.

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