Populate values from one field to another field

Revathi12
Tera Contributor

I have 2 fields "Existing groups" & "Remove Existing" and both are of type List Collector. Currently existing groups having values populated with the groups where the user have. I need to have the same values populated in the remove existing field. Please help

 

Thanks!

3 REPLIES 3

_Gaurav
Kilo Sage

Hi @Revathi12 
You can either write an onChange client script to set the value or the before BR based on your requirement.

onChange CS where you have to select the field as an existing group.
g_form.setValue('remove_existing', newValue);

Or before BR

current.remove_existing = current.existing_group;

 

 

Please hit helpful and accepted as a solution if this resolves your query.

Thanks!

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Revathi12 , 

 

You can go with onLoad client script.

function onLoad() {
    var existingGroups = g_form.getValue('existing_groups'); // Assuming 'existing_groups' is the field name for "Existing Groups"
    var removeExistingField = g_form.getControl('remove_existing'); // Assuming 'remove_existing' is the field name for "Remove Existing"
    
    // Clear existing values in 'Remove Existing' field
    removeExistingField.innerHTML = '';

    // Populate 'Remove Existing' field with the same values as 'Existing Groups'
    if (existingGroups) {
        existingGroups.forEach(function(group) {
            var option = document.createElement('option');
            option.text = group.display_value;
            option.value = group.value;
            removeExistingField.add(option);
        });
    }
}

 

Please mark as Accepted as Solution & hit helpful !!! 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Anubhav24
Mega Sage
Mega Sage

Hi @Revathi12 ,

Please refer to below article for setting up of dynamic values in list collector by @Ankur Bawiskar ,

https://www.servicenow.com/community/developer-blog/dynamically-set-list-collector-on-change-of-vari...

 

Please mark helpful/correct if my response helped you.