Is there a way to make a utility function that returns a sub-row from the main row

Is there a way to make a utility function that returns a sub-row from the main row

Does anyone know if there's a way to achieve this in zoho?

I've got two subforms on my main form, and the second one has a dropdown that's populated with a list of unique id's from the first. A common task that I have is that I need to get information from the related row, so I thought that as I need to do this a lot, I'd make a function to do it for me. But I can't get it to work. I've tried returning a collection, but that fails, I can't find a way to cast an object to a specific type. And this needs to work on new records, i.e. the submit button hasn't been pressed yet.

  1. PrintPublication Utility.GetPublicationRow(PrintBooking Booking, string pubid)
  2. {
  3. c = null;
  4. for each  p in Booking.Publications
  5. {
  6. if(p.PublicationID == toLong(pubid))
  7. {
  8. c=p;
  9. }
  10. }
  11. return c;
  12. }