Tip for quick record lookups.

Tip for quick record lookups.

Here's a little trick I'm using to speed up subsequent look ups of records on a form. 

1. Problem.. 

You've dynamically pulled in a list of records into a radio box selection. You want to use the selected radio button's value to do a lookup on another record (The record you just pulled in). BUT the value in the radio button is something not very unique like a vanity date or a location or something of that nature. This will make getting that record more difficult. 

2. Solution.. 

Embed the records ID as a hidden span like so.. 

  1.  sessionRecords  =  sess_scheduler  [(start_timestamp >= time && location = c.Location)]
  2.             vanitySessions = {};
  3.             for each r in sessionRecords
  4.             {
  5.                 v = thisapp.helper.vanityDate(r.start_time);
  6.                 v = v + "<span style='display:none'>{{" + r.ID + "}}</span>";
  7.                 vanitySessions.add(v);
  8.             }
  9.             session_choice:ui.add(vanitySessions);

Now instead of having to due a very nebulous lookup on just the radio buttons value. You can use the actual records ID..

  1.     session_id = input.session_choice.toString().getSuffix("{{").getPrefix("}}").toLong();

To take it a bit further you could just embed a record map().toString(), basically a json string, in the hidden span and turn it back into a map when someone selects the radio button. I used the <span>{{}}<span> style just because it makes for easy parsing. But if you wanted to go the real html route you could add the value(s) as html5 attributes.. Example

  1. recordMap =  {field1 : r.field1, field2 : r.field2};
  2. v = v + "<span data-record=\""+recordMap.toString()+"\"></span>";

Ok, just thought I would share. Hope someone finds good use out of this ;)

-SRhyne