How can I write an Array in a Business Rule based on a form selection?

paul971
Mega Expert

Hi all -

We have a List field on a form and the user needs to be able to select one or more for the slushbucket. On the backend I need the value of the selection to send in a SOAP message. However, I have a requirement for the name to be displayed...

Example:

type: 'Apple' , 'Banana' - what the customer needs to see on the form

value of type: 'A, B' - what i need to send

what is the best way to go about doing this? do i need a hidden field that gets the value of the selected? should i set up an array in the business rule on that field? This got way too complicated. Att the end of the day the user needs to see the selection and i need the value of that selection.

22 REPLIES 22

Chuck Tomasi
Tera Patron

Hi Paul,



If you're dealing with a list field, the user sees the display value. List fields are like reference fields that can hold multiple items. Internally, it is storing just a list of sys_ids, so the value is going to be what you get when you get the value from the field using the getValue() method.



Something like:



var fruit = current.getValue('u_fruit'); // returns a comma separated list of sys_ids to the records.



I hope that makes sense. If not, let me know.


Thanks ctomasi!



I would love to do that, but...the list is set up so it references another table which holds the values. This table is simple,   just two columns,   Name and value (i.e. Apple and A, etc), FYI they are both string fields on this table and the name is set as the display value on that table. Which is why I think this is not so straight forward. I think I need to make a call to the table and pull the "value" of what is selected.



... sorry if that's confusing


Thanks. I get it. You've got a comma separated list of sys_ids to the other table. Yes, you will need to retrieve the data from the other table to get the "A" value.



Completely untested code ahead and it makes some assumtions about the fields and tables, but you should get the idea.



var fruit = current.getValue('u_fruit'); // get the sys_ids


var fruitArr = fruit.split(',');


var fruitVal = [];



for (var i = 0; i < fruitArr.length; i++) {


    var f = new GlideRecord('u_fruit_table');


    if (f.get(fruitArr[i])) {


        fruitVal.push(f.getValue('u_value'))'


  }


}



// fruitVal is now an array of values. If you want it back to a comma separated string...


var returnString = fruitVal.join(',');


Abhinay Erra
Giga Sage

Use getDisplayValue().


current.variables.<variable_name>.getDisplayValue();