Reference Field Calculate Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 01:51 PM
What value do I return for a Reference Fiend Calulcation?
Here is what I have so far;
I have a reference field to "Group"
Having this:
(function calculatedFieldValue(current) {
return "bbda81eddbdc1cd0ce30f1471d961996";
})(current);
Returns nothing. (that is the sys_id for a group called ISSE)
(function calculatedFieldValue(current) {
return "ISSE";
})(current);
Returns Nothing as well.
Also can this return an Array of values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 04:15 PM
I guess no one knows?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 04:51 PM
It should work the way you wrote it. Reference fields contain the literal string of the sys_id of the referenced record. I wrote it like this on a reference field to the Change Request table. The sys_id you provide must match a record that really exists in the target table obviously. If I change the sys_id slightly then it breaks and doesn't show anything in the field.
(function calculatedFieldValue(current) {
// Add your code here
return '3f706823dba800104bb828f3ca96198d'; // return the calculated value
})(current);
To answer your second question, "no", Reference fields cannot support passing an array as they only support using one value. You could look at a GlideList field type for multiple values. Ideally if you need multiple references though, it is best to use a reference field on the other table and use a related list. Or if you need a *:* situation, then create a M2M table. The GlideList field type violates the principles of database normalization - a whole different conversation...
I have to conclude that either you have some other logic that is wiping out your calculated value (client script?) or perhaps your sys_id isn't really a valid record. What happens if you put debugging code in your calculated value field like the following? Is it running?
gs.log("I am calculating stuff!")