# How to sync multiselect type field in default if the options not matched destination side

**URL:** <https://community.exalate.com/t/how-to-sync-multiselect-type-field-in-default-if-the-options-not-matched-destination-side/5250>\
**Category:** General Questions\
**Tags:** onpremise-jira, exalate, jira, migrated\_question, syncing\
**Created:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/how-to-sync-multiselect-type-field-in-default-if-the-options-not-matched-destination-side/5250 "2024-11-04T07:53:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/how-to-sync-multiselect-type-field-in-default-if-the-options-not-matched-destination-side/5250/1 "2024-11-04T07:53:23Z")

</div>

_Originally asked by Moogambigai G R on 01 July 2022 [(original question)](https://oldcommunity.exalate.com/questions/58491779)_

* * *

Hi Team,

We have a scripted connection for project A and Project B in local instance and below are the example configuration.

```auto
Outgoing:

if (issue.project.key == "DAR" && issue.typeName == "Defect"){

replica.customFields."10806" = issue.customFields."10806" //Accoutable Team//OEM Accountable Team  
}

Incoming:

if(replica.project.key == "DAR" && replica.type.name == "Defect") //sync A -> B  
{  
issue.projectKey = "OEM"  
  
def issueTypeMapping = ["Defect" : "Acquired Product Defect"]

issue.typeName = issueTypeMapping[replica.type?.name] ?: "Acquired Product Defect"

if (issue.projectKey == "OEM")
{
def aTeam = replica."10134"?.value
if ((aTeam != "Alexandra") && (aTeam != "Canyon")&&(aTeam != "Carroll") && (aTeam != "Carroll-Ref")&& (aTeam != "Melody")&& (aTeam != "Mystic"))
{
issue.customFields."17003"?.value = "Alexandra"
}
else{
issue.customFields."17003".value = replica.customFields."10134".value
}}

```

We have Multi List type field and some values only matching in both sides, Need a functionality like if any of the not available values in project B field is selected in Project A while syncing A-\>B default value to be set.

Example

Project A -\>Have “Alder” value

Project B → Not have “Alder” Value

If I synced A-\>B ---\>I have to set default value, if value is not present otherwise it will set the same value as A in B Project.

Regards,

Moogambigai G R

* * *

#### Comments:

> **Moogambigai G R commented on 07 July 2022**
>
> > Hi Team,
> 
> Is there any update on above question?
> 
> Regards,
> 
> Moogambigai G R

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/how-to-sync-multiselect-type-field-in-default-if-the-options-not-matched-destination-side/5250/2 "2024-11-04T07:53:25Z")

</div>

_Answer by Ezequiel Consorti on 06 September 2022_

Hi Moogambigai, As mentioned in the support ticket after testing the following script and confirming that it works properly I am posting the solution here as well in case other members of our community encounter similar issues.

Outgoing sync:

```auto
if(issue.project == "ProjectKey"){
    replica."Affected Programs 2" = issue."Affected Programs 1"
}else{
    replica."Affected Programs 1" = issue."Affected Programs 2"
} 

```

Incoming sync:

```auto
Option 1:

if(replica.project.key == "ProjectKey1"){
    def defaultOption = nodeHelper.getOptions(issue, "Affected Programs 2", ["DefaultValue"])
    def options = nodeHelper.getOptions(issue, "Affected Programs 2", replica."Affected Programs 2".collect { it -> it.value }).findAll { it != null} if(options == null || options.size() == 0) {
        issue.customFields."Affected Programs 2".value = defaultOption
    } else {
        issue.customFields."Affected Programs 2".value = options
    }
}
if(replica.project.key == "ProjectKey2"){
    def defaultOption = nodeHelper.getOptions(issue, "Affected Programs 1", ["DefaultValue"])
    def options = nodeHelper.getOptions(issue, "Affected Programs 1", replica."Affected Programs 1".collect { it -> it.value }).findAll { it != null} if(options == null || options.size() == 0) {
        issue.customFields."Affected Programs 1".value = defaultOption
    } else {
        issue.customFields."Affected Programs 1".value = options
    }
}

Option 2:

if(replica.project.key == "ProjectKey1"){
    def defaultOption = nodeHelper.getOptions(issue, "Affected Programs 2", ["DefaultValue"])
 
    issue.customFields."Affected Programs 2".value = nodeHelper.getOptions(issue, "Affected Programs 2", replica."Affected Programs 2".collect { it -> it.value }).findAll { it != null} ?: defaultOption
}
if(replica.project.key == "ProjectKey2"){
    def defaultOption = nodeHelper.getOptions(issue, "Affected Programs 1", ["DefaultValue"])
 
    issue.customFields."Affected Programs 1".value = nodeHelper.getOptions(issue, "Affected Programs 1", replica."Affected Programs 1".collect { it -> it.value }).findAll { it != null} ?: defaultOption
} 

```

Kind regards.  
Ezequiel

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/how-to-sync-multiselect-type-field-in-default-if-the-options-not-matched-destination-side/5250/3 "2024-11-04T07:53:25Z")

</div>

_Answer by M. Ashar Iqbal on 07 July 2022_

Hi Moogambigai G R ,

Could you please try the [getOption](https://docs.idalko.com/exalate/x/0wBf) method, and let me know if it does not comply with your requirement?

Thank you,

Ashar

* * *

#### Comments:

> **Moogambigai G R commented on 11 July 2022**
>
> > Hi M. Ashar Iqbal
> 
> I have tried with getoption, its throwing error and its a multi select type field.
> 
> Requirement is if the values matches both side, it should sync that value, if not default values should sync.
> 
> Attached support zip. [exalate\_support\_5.3.1-j8\_8.20.6\_20220711-025716.zip](https://oldcommunity.exalate.com/download/attachments/58491779/exalate_support_5.3.1-j8_8.20.6_20220711-025716.zip?version=1&modificationDate=1657522953791&api=v2)_(old community)_
> 
> Regards,
> 
> Moogambigai

> **Moogambigai G R commented on 13 July 2022**
>
> > Hi Ashar,
> 
> Is there any update?
> 
> Regards,
> 
> Moogambigai

> **Moogambigai G R commented on 14 July 2022**
>
> > Hi Ashar,
> 
> Is there any update on my above comment?
> 
> Regards,
> 
> Moogambigai

> **Ariel Aguilar commented on 14 July 2022**
>
> > Hi Moogambigai,
> 
> You can try something like in the following example:
> 
> ```auto
> issue.customFields."A".value = replica.customFields."B".value ?: "Default Value"
> 
> ```
> 
> Kind regards,
> 
> Ariel

> **Moogambigai G R commented on 15 July 2022**
>
> > Hi Ariel Aguilar
> 
> Thanks for the update. Please find below are the results i’m getting,
> 
> **Local connection:**
> 
> outgoing:
> 
> replica.customFields.“10134” = issue.customFields.“10134” //Affected Programs // OEM Affected Programs
> 
> Incoming:
> 
> issue.customFields.“17401”.value = replica.customFields.“10134”.value ?: “Alexandra”
> 
> 10134 -Project A multiselect type field
> 
> 17401 -Project B multiselect type field
> 
> Scenario 1:
> 
> **Same values available in both side:**
> 
> Here I have selected “carroll,canayon” in 10134 field and synced the record and values are synced perfectly
> 
> Scenario 2:
> 
> **One value has available in both side, one non-value selected:**
> 
> Selected Brilliance,Carroll in 10134 field and synced the record, its emptied the field in destination records and not setting default value as “Alxendra”
> 
> Scenario 3:
> 
> **Non-matched values selected:**
> 
> Selected Brilliance in 10134 field and synced the record, its emptied the field in destination records and not setting default value as “Alxendra”

> **Moogambigai G R commented on 18 July 2022**
>
> > Hi Ariel Aguilar
> 
> Is there any update on my last comment?
> 
> Regards,
> 
> Moogambigai

> **Ariel Aguilar commented on 18 July 2022**
>
> > Hi there,
> 
> If you try:
> 
> ```auto
> issue.customFields."17401".value = replica.customFields."10134".value ?: ["Alexandra"]
> 
> ```
> 
> Kind regards,
> 
> Ariel

> **Moogambigai G R commented on 19 July 2022**
>
> > Hi Ariel Aguilar
> 
> Thanks for the update, I have tried above method, still no luck.
> 
> Both side same values is there only its sync, if values didn’t match its cleared the existing value and not setting default value.
> 
> See the below history images both local and remote issues.
> 
> ![](https://dub1.discourse-cdn.com/flex018/download/attachments/58491779/DAR%20project%20outgoing%20record.PNG?version=1&modificationDate=1658209855249&api=v2) ![](https://dub1.discourse-cdn.com/flex018/download/attachments/58491779/OEM%20Project%20incoming%20result.PNG?version=1&modificationDate=1658209855628&api=v2)
> 
> Regards,
> 
> Moogambigai

> **Moogambigai G R commented on 20 July 2022**
>
> > Hi Ariel Aguilar
> 
> Is there any update on my last comment?
> 
> Regards,
> 
> Moogambigai

> **Ariel Aguilar commented on 20 July 2022**
>
> > Hi there,
> 
> And if you do:
> 
> `issue.customFields.``"17401"``.value = replica.customFields.``"10134"?``.value ?: [``"Alexandra"``]`
> 
> `Kind regards,`
> 
> `Ariel`

> **Moogambigai G R commented on 21 July 2022**
>
> > Hi Ariel Aguilar
> 
> I have tried below one also and tried to replaced the field name instead of custom id. Nothing working.
> 
> `issue.customFields.``"17401"``.value = replica.customFields.``"10134"?``.value ?: [``"Alexandra"``]`
> 
> `Regards,`
> 
> `Moogambigai`

> **Ariel Aguilar commented on 21 July 2022**
>
> > This is not expected, if you try the following:
> 
> ```auto
> def defaultOption = nodeHelper.getOptions(issue, "17401L", ["Alexandra"])
> 
> issue.customFields."17401".value = replica.customFields."10134"?.value ?: defaultOption
> 
> ```
> 
> Kind regards,
> 
> Ariel

> **Moogambigai G R commented on 22 July 2022**
>
> > Hi Ariel Aguilar
> 
> I have tried above method also, but result is same, if values is not matched in local side, its not setting default value, its setting null.
> 
> If its possible, can we setup a meeting to resolve this issue.
> 
> Regards,
> 
> Moogambigai G R

> **Ariel Aguilar commented on 22 July 2022**
>
> > Hi Moogambigai,
> 
> Please [submit a support request](https://support.idalko.com/servicedesk/customer/portal/8) to our Service Desk directly to investigate for a possible bug.
> 
> Or just send an e-mail to [support@exalate.com](mailto:support@exalate.com). This will create an issue on our JIRA Service Desk allowing for further tracking.
> 
> Kind regards,
> 
> Ariel
