Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

I fixed a couple syntax errors and added the name array as well.



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


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


var fruitVal = [];


var fruitName = [];



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


        fruitName.push(f.getValue('u_name'));


}



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


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


var returnName = fruitName.join(',');


As far as I know, the default separator is comma (,) for join. So we don't need join(','). Correct me if I am wrong.


You are correct. I just like it there to make it more readable. Shortcuts in code can be confusing to future readers. Perl programming taught me that.


I agree


actually, sadly it didnt work. same error



getting this message today...


<faultstring>Failed to validate request.


cvc-enumeration-valid: Value '55a337506f42020050752df23e3ee407' is not facet-valid with respect to enumeration '[A, B, P,]'. It must be a value from the enumeration.</faultstring>