Sync the value of an Insight Custom Field to a Select List (cascading)

Originally asked by Samuel Carter on 05 October 2023 (original question)


I would like to split the value of the Insight Field over the Select List (cascading field).

For example the value of my Insight Field is HelloThere, when it syncs over to the other instance, I would like Hello to be the first value in the select list, and There to be the second value in the select list.

Is this possible? What would the groovy look like for that?

Much appreciated.


Comments:

Francis Martens (Exalate) commented on 06 October 2023

Iā€™m a bit confused about the question - is it about splitting a string, or about extracting a particular value from an Insight Field and put it in a select list.

Francis Martens (Exalate) commented on 10 October 2023

Hi Samuel Carter - can you check out my question?

Samuel Carter commented on 12 October 2023

Hi Francis Martens (Exalate),

Apologies I missed your initial reply.

Itā€™s a bit of both. I want the value from the Insight Field to be extracted, and then split that value into the two sections of a cascading select list.

Does that make sense?

Thanks,

Sam

Answer by Francis Martens (Exalate) on 12 October 2023

We are experimenting with a customised Chatgpt chatbot - check out the details

I would like to split the value of the Insight Field over the Select List (cascading field).For example the value of my Insight Field is HelloThere, when it syncs over to the other instance, I would like Hello to be the first value in the select list, and There to be the second value in the select list.Is this possible? What would the groovy look like for that?Much appreciated.

Yes, it is indeed possible to split the value of your Insight Field over to a Select List (cascading field) in Jira Cloud. For instance, given that the value is ā€œHelloThereā€ and you want to split it so ā€œHelloā€ becomes the parent and ā€œThereā€ becomes a child option, you will need to configure both the Outgoing and Incoming sync as follows:

  1. First, configure the Outgoing sync to send your Insight field value:
replica.customFields."InsightField" = issue.customFields."InsightField"

2. Afterward, in the Incoming sync, you should extract the value from your Insight Field and form the parent-child select list values:

 


    def insightFieldValue = replica.customFields."InsightField".value
    def splitValues = insightFieldValue.split("(?<=Hello)")
    def parent = nodeHelper.getOption(issue, "Cascading select", splitValues[0])
    issue.customFields."Cascading select".value = nodeHelper.getCascadingSelect(parent, parent.childOptions.find{it.value == splitValues[1]})


Note: In the split function, replace ā€œHelloā€ with the actual parent value you expect in your use case.

Make sure to replace ā€œInsightFieldā€ and ā€œCascading selectā€ with the actual field names in your case.

This script will first split the Insight Field value into two parts based on your delimiter (ā€œHelloā€ in this case). Then it retrieves the parent option and combines it with the child option to form the cascading select field value at the destination side.

*Remember to check the sync scope and ensure you have permissions to access the custom fields. Also, the ā€˜parent.childOptions.findā€™ function expects the child option to exist; you might want to extend this script to handle the scenario when the child option doesnā€™t exist.

Find further details on handling custom fields sync in the Exalate documentation: https://docs.exalate.com/docs/how-to-sync-cascading-select-custom-fields-in-jira-cloud

The insightfield has a structure and it is not necessarily ā€˜valueā€™ that contains the value

Indeed, an Insight custom field has a specific structure, which is not a simple ā€˜valueā€™ but rather a set of items (objects) and attributes.

The synchronization of Insight fields is done by assigning the string representation of the Insight object to a custom field on the replica. The same process applies on the destination side where we set the value of an Insight custom field equal to the value coming from the source.

Hereā€™s an example of how to set a single Insight object to a target Insight custom field:

Outgoing from Source Side:

if(issue.customFields."Insight Field Name".value != null){
    replica.customFields."Insight Field Name" = issue.customFields."Insight Field Name".value.inspect()
}

Incoming to Destination Side:
(note that that class is only valid on Jira On Premise)

issue.customFields."Insight Field Name".value = com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade.loadObjectBean(replica.customFields."Insight Field Name".value)


I should mention that the example I have given you here is a basic setup that only considers the primary object of the Insight field. If you have several objects or want to extract values from your Insight objectā€™s attributes or references, you will need to adapt your script accordingly.

Please check the Exalate documentation for more guidance on how to sync Insight custom fields: https://docs.exalate.com/docs/how-to-sync-insight-custom-fields


Comments:

Francis Martens (Exalate) commented on 12 October 2023

This is an example of a response from a finetuned Chatgpt trained on the documentation of Exalate.

Samuel Carter commented on 16 October 2023

Thanks Francis Martens (Exalate) Iā€™ll give this a go.