We have a specific business requirement for our Jira-to-Jira integration using the Exalate plugin and are looking for your guidance on the best way to script it.
Our Current Setup:
Whenever an issue is synced from the Source instance to our Destination instance, we capture the source project’s name using replica.project?.name. This value is populated into a custom Select List field named “Source” on the destination side.
Our Requirement:
For security and privacy reasons, we need to mask certain source project names. Instead of displaying their real names in the destination “Source” field, we want them to appear as “Roomed”.
If the source project is on our “mask list”, the destination field should be set to “Roomed”.
If the source project is not on that list, it should continue to display its real project name as it does currently.
Could you please review our intended approach and provide the recommended, production-ready Groovy script snippet for our Incoming Sync script? Specifically, we want to ensure we handle nodeHelper.getCustomFieldOption correctly so it doesn’t throw errors if a value is null or mismatched.
You can achieve this requirement in your Incoming Sync script by defining a list of project names that should be masked. Then, use a conditional to check if the incoming project name is in that list. If it is, set the custom field to “Roomed”; otherwise, use the actual project name. To safely set a Select List field, use nodeHelper.getCustomFieldOption and handle cases where the value might not exist.
Here’s a production-ready Groovy snippet for your Incoming Sync script:
// List of project names to be masked
def maskList = ["Sensitive Project 1", "Secret Project 2", "Confidential XYZ"]
// Get the source project name from the replica
def sourceProjectName = replica.project?.name
// Determine the value to set
def fieldValue = maskList.contains(sourceProjectName) ? "Roomed" : sourceProjectName
// Safely get the custom field option
def sourceOption = fieldValue ? nodeHelper.getCustomFieldOption("Source", fieldValue) : null
// Set the custom field if the option exists
if (sourceOption) {
issue.setCustomFieldValue("Source", sourceOption)
} else {
// Optionally, clear the field or handle missing option
issue.setCustomFieldValue("Source", null)
}
This script ensures:
Only projects in your mask list are replaced with “Roomed”.
The custom field is set using nodeHelper.getCustomFieldOption, which avoids errors if the value is null or doesn’t match an existing option.
If the option doesn’t exist, the field is cleared (you can adjust this behavior as needed).