Shafik Walakaka
Shafik Walakaka

Reputation: 1

workflow to update issue state in target project, on change of issue state in source project

Summary

We have two projects:

When customer raises an issue, the issue is raised in the Support Project. This automatically creates an issue in the Developer project with the relevant tags.

The issue created in the Developer project will have summary <support-issue-summary>/<support-issue-id>.

Currently, we are unable to automatically update states in the Support project based on change in state in the Developer project. Details are as follows:

Requirements

Our development team only reviews the Developer project. We want to sync changes in states in the Developer project to automatically update the relevant issue in the Support project.

The Developer and Support project should have separate states.

Implementation

After verifying the guard, and obtaining the relevant target issue ID etc. We use this try catch block to update the target issue state:

    // this version is working
    try {
      // If the current state of the linked issue is 'UAT-QAClosed', make it 'Pending Release'
      if(issue.fields.State.name === "UAT-QAClosed") {
        console.log("start to update the field...")
        targetIssue.fields.State = ctx.HelpDesk_State["InProgress"];
        }
    } catch(err) {
      console.log(JSON.stringify(err));
      console.log("Damn, this means there is an error...");
    }

Requirements block, for reference:

  requirements: {
    StateState: {
      name: "State",
      type: entities.State.fieldType,
      UATQAClosed: {name: "UAT-QAClosed"},
      "Pending Release": {name: "Pending Release"},
      InProgress: {name: "In Progress"},
      "SIT-Closed": { name: "SIT-Closed" } // New mapping
    },
   
   HelpDesk_State: {
      name: "State",
      type: entities.State.fieldType,
      UATQAClosed: {name: "UAT-QAClosed"},
      "Pending Release": {name: "Pending Release"},
      InProgress: {name: "In Progress"},
      "SIT-Closed": { name: "SIT-Closed" } // New mapping
    },
    
    project_0: {
      type: entities.Project,
      name: 'Test Project 14 Mar'
    }
}

Success -- If share same State Field

The target issue is updated successfully if both the Developer and Support project shares the same state fields

See here for reference!

Issue -- require assistance

However, when the fields are independent -- the try-catch block throws an error.

However, the error is undefined

Workaround

Currently, the workaround is to have both the Developer and Support project to use the exact same states. However, this is not a feasible option for us -- and we'd like to check in on any ways we can improve this?

Upvotes: -1

Views: 443

Answers (1)

Julia Bernikova
Julia Bernikova

Reputation: 36

this is Julia from YouTrack Support.

The issue seems to be with the requirements section of the rule. There's currently no way to declare project-specific requirements: the entire section applies to every project the workflow is attached to. Basically, YouTrack expects the "State" field in the "Developer" project to contain the values from both StateState and HelpDesk_State. The same applies to the "Support" project if you attached the workflow there as well.

To work around the issue, first change the requirements section so that it only contains the expected "State" field values for the "Developer" project. Then, change the rule so that the ticket state in the "Support" project is changed somehow like this:

  const stateMapping = {
    "UAT-QAClosed": "Pending",
    "SIT-Closed": "Solved"
    // Some other state mappings (from Developer to Support)
  }
  const targetState = stateMapping[issue.fields.State.presentation];
  const targetStateValue = entities.Project.findByName("Support").findFieldByName("State").findValueByName(targetState);
  if (targetStateValue) {
    console.log("start to update the field...")
    targetIssue.fields.State = targetStateValue;
  }

If you need the sync to be two-way, create another on-change rule in the "Support" project and change the "Developer" issue states from there using the same approach.

As for the error, you can call console.log(String(err)) to log the exception text or even temporarily remove the try...catch block to see the exception with the full stack in the console.

Upvotes: 0

Related Questions