Pass a record to a function

Pass a record to a function

I have forms that represent categories and subcategories of items. I allow users to drill down into groups, categories, and subcategories, etc. I'm using a Rich Text field in each record to create a set of hyperlinks to go back to the parent records. For example: Group -> Category -> Subcategory. I group my reports by this field and users can click on any level to go back.

I find myself repeating similar code for populating the Rich Text field in all of these forms. Is it possible to pass a record to a function? For example:
  1. parentRec  =  Cat1  [ID == input.Cat1];
  2. rtLinkBack = LinkBack(parentRec, "Cat1");
Right now I do this in each form:
  1. parentRec  =  Cat1  [ID == input.Cat1];
  2. parentView = "View:Cat1_Report";
  3. filter = "slParentID=" + parentRec.slParentID;
  4. title = "Back";
  5. input.slParentID = parentRec.ID.toString();
  6. input.rtBack = parentRec.rtBack + " -> " + thisapp.Hyperlink(parentView, filter, title, parentRec.Name);
Thanks