I think this has been covered before, but I sure can’t find it.
I’m creating an event processor that is fired when a record is created. Nothing special, but the first thing I need to do is get the text value from a Choice field. This is what I have so far:
var leg_recid = params.record_id;
var leg_type = mats.record(leg_recid).get(['OCC_Ref_Fld_leg_type']);
mats.log('Rec type = ' + JSON.stringify(leg_type));
var leg_type_text = mats.displayable('OCC_Ref_Fld_leg_type', leg_type);
mats.log('Rec type text = ' + leg_type_text);
mats.log('Rec type text = ' + JSON.stringify(leg_type_text));
Looking at the log in Detective I see:
- 10:37:44.3384 Saved Record 110085 (OCC>Legislation Record) in 0.0094s
- 10:37:44.3392 Event Record created triggered on Record 110085 (OCC>Legislation Record)
- 10:37:44.3407 Rule OCC>Generate Legislation Record Number triggered for Record 110085 (OCC>Legislation Record)
- 10:37:44.3438 *** Entering OCC>Generate Legislative Record Number
- 10:37:44.345 Invalid field path - “:OCC_Ref_Fld_leg_type” (occurred 2 times)
******* Note this error - the field path is not invalid, and the record is returned. Bug?**
- 10:37:44.3452 Rec type = {“OCC_Ref_Fld_leg_type”:“DTC0000112DCDCA1”}
- 10:37:44.3453 Rec type text = [object Array]
- 10:37:44.3454 Rec type text = {“OCC_Ref_Fld_leg_type”:“DTC0000112DCDCA1”}
So, a couple of things.
-
record.get() is throwing an error on the field reference, but seems to be returning the field anyway. Not sure this is related or if it is a bug.
-
mats.displayable isn’t throwing any errors, but, based on the log, doesn’t appear to do anything - I get back exactly what I put in.
Please feel free to point out stupid errors!
Thanks,
Randy
Hi Randy,
I’ve got a couple of suggestions to try!
var leg_type = mats.record(leg_recid).get('OCC_Ref_Fld_leg_type');
This removes the square brackets as you aren’t passing in an array and that may be causing a problem.
Or…
mats.record(leg_recid).get(mats.ref('OCC_Ref_Fld_leg_type'));
This is using the ref function to return the field path.
Richard
Also the get function takes a second parameter, either editable or displayable!
Thanks for the suggestions. I tried ‘em both as follows:
var fred = mats.record(leg_recid).get(‘OCC_Ref_Fld_leg_type’, ‘displayable’);
mats.log('fred = ’ + fred);
var barney = mats.record(leg_recid).get(mats.ref(‘OCC_Ref_Fld_leg_type’, ‘displayable’));
mats.log('barney = ’ + barney);
But, the results are the same, I get the ID (in displayable format) of the selected choice. I get the same results replacing ‘displayable’ with ‘editable’ .
11:56:20.7088 fred = DTC0000115DCDCA1
11:56:20.7096 barney = DTC0000115DCDCA1
There might be a bug in the Reference processing code, but I couldn’t say if it would cause this issue. Whenever I use a Field Path Reference I see errors in the Detective like these:
12:01:45.0914 fred = DTC0000113DCDCA1
12:01:45.0923 barney = DTC0000113DCDCA1
12:01:45.093 Invalid field path - “:OCC_Ref_Fld_leg_type_text” (occurred 2 times)
I haven’t reported it, officially, yet because I’m still not sure I’m not causing the problem.
Regards,
Randy
Got it. I’d swear that I tried this, but I either did it wrong, or I - something else.
Anyway, this works:
var barney = mats.record(leg_recid).get(mats.ref(‘OCC_Ref_Fld_leg_type’, ‘editable’));
mats.log('barney = ’ + barney);
var betty = mats.displayable(‘OCC_Ref_Fld_leg_type’, barney);
mats.log('Betty = ’ + betty);
Producing these results:
- 17:51:50.0902 barney = DTC0000117DCDCA1
- 17:51:50.0907 Betty = Resolution
Regards,
Randy
1 Like
Congratulations @groswald, it seems like burning the midnight oil paid off!
Cheers, Tony