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

Thanks abhi_r ,



on my table the list is referencing, the name is set as the display value. I need to pull the value of the name from the other table, which is another column.


Sorry, I am confused here. Can you give an example illustrating what you need.


sure. example below.



I need the "Name" to display, though the Value is set as my display value. The reason being, I need to send the value in a SOAP message once this form is submitted.



find_real_file.png


I should have you covered. If you want both the value and the name, add another array to my script and push the value of the name field in to it along with the value.


Just a minor chnage to chuck's code. Instead of looping it, you can use IN operator in query as shown below for better performance.



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


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


var fruitVal = [];



    var f = new GlideRecord('u_fruit_table');


    f.addQuery('sys_id','IN',fruitArr.join());


    f.query();


  while(f.next()){


        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(',');