How can I write an Array in a Business Rule based on a form selection?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 09:51 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 10:42 AM
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(',');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 10:48 AM
As far as I know, the default separator is comma (,) for join. So we don't need join(','). Correct me if I am wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 10:52 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2016 10:54 AM
I agree
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 09:09 AM
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>