To map values from list collector variable to a choice field on the table

Pravallika1
Giga Guru

Hi!!

I am facing issue on how to map the values from a list collector field in a record producer to a choice field on a custom table.

I have a list collector field which contains some state values and the custom table contains those state values as choice fields with choices 'Yes , No'.

I have to map the state values selected in the list collector field to the choice fields with values as 'No'. i.e, if there are two choices selected in list collector(Alaska , Alabama) , I should update the choice fields Alaska , Alabama with 'No' as choice value.

And I should also map the states from Available slushbucket to the choice fields with value as 'Yes' on the custom table.

1.

Pravallika1_0-1708532582910.png

2.

Pravallika1_1-1708533110134.png

 

 

From the screenshot 1, we should map the choice fields 'Alabama & Alaska' to 'No' and the values 'Colorado,New York,Indiana,Florida,Hawaii,Michigan,Montana' to 'Yes' on their respective choice fields referenced on screenshot 2.

 

Note: From the screenshot 1, display users field contains the all the values from left slushbucket.

Please do follow the link - Re: Copy List collector values to a multi line tex... - Page 2 - ServiceNow Community for more context.

Please do help me with the solution.

Thanks in advance!!

1 ACCEPTED SOLUTION

Pravallika1
Giga Guru

Thanks for your reply!!

I used this approach to achieve my requirement-

Called the script include function in record producer script-

Record producer script -

var statesUpdate = new Partner_Utils().updateFields(producer, current);
Script Include-
updateFields: function(producer, current) {
var selectedValues = producer.list collectro field backend name.getDisplayValue().split(',');
        for (var i = 0; i < selectedValues.length; i++) {
            var fieldName = 'u_' + selectedValues[i].trim().toLowerCase();
            fieldName = fieldName.replace(".", "").split(" ").join("_");
            current.setValue(fieldName, 'no'); //To populate no in selected fields
        }


        var sValues = producer.multi line text field backend name.getDisplayValue().split(',');
        for (var j = 0; j < sValues.length; j++) {
            var fieldNames = 'u_' + sValues[j].trim().toLowerCase();
            fieldNames = fieldNames.replace(".", "").split(" ").join("_");
            current.setValue(fieldNames, 'yes'); // To populate yes in non selected fields
        }
},

View solution in original post

4 REPLIES 4

Pravallika1
Giga Guru

@Akash Gupta2 @Ankur Bawiskar @Sohithanjan G 

Anybody Can you please help me this code. I am unable to solve this requirement.

Please do help me

Thanks in Advance!!

Ankur Bawiskar
Tera Patron
Tera Patron

@Pravallika1 

should be an easy task using workflow script.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Can you please provide with the code.

Can you also please suggest another way other than workflow script.

Can you please assist with code if this can be done through BR.

Thanks in Advance!!

Pravallika1
Giga Guru

Thanks for your reply!!

I used this approach to achieve my requirement-

Called the script include function in record producer script-

Record producer script -

var statesUpdate = new Partner_Utils().updateFields(producer, current);
Script Include-
updateFields: function(producer, current) {
var selectedValues = producer.list collectro field backend name.getDisplayValue().split(',');
        for (var i = 0; i < selectedValues.length; i++) {
            var fieldName = 'u_' + selectedValues[i].trim().toLowerCase();
            fieldName = fieldName.replace(".", "").split(" ").join("_");
            current.setValue(fieldName, 'no'); //To populate no in selected fields
        }


        var sValues = producer.multi line text field backend name.getDisplayValue().split(',');
        for (var j = 0; j < sValues.length; j++) {
            var fieldNames = 'u_' + sValues[j].trim().toLowerCase();
            fieldNames = fieldNames.replace(".", "").split(" ").join("_");
            current.setValue(fieldNames, 'yes'); // To populate yes in non selected fields
        }
},