Sort 'searchRecordsByPDC' results by Date field

Sort 'searchRecordsByPDC' results by Date field

I am using the below code to fetch all CRM 'PurchaseOrders' records from a specified CRM 'Potential' and then insert them as SubRow items "On Success"

At the moment they are inserted in their default order, however I need them to be saved in a custom date order (Start Date).

What is the easiest way to sort the fetched record for inserting in the SubForm?

  1. var1 = input.ID;
  2. //pull data from CRM based on Potential id
  3. srch = zoho.crm.searchRecordsByPDC("PurchaseOrders", "Potential Name_ID", input.Bookid);

  4. //for each index in data retrieved, allocate the field to variable and then insert the variables into as new subform record and associated with the main form using ID
  5. for each index res in srch
  6. {
  7.     vend = srch.get(res);
  8.     vend_name = vend.get("Vendor Name");
  9.     start_date = vend.get("Start Date");
  10.     vend_id = vend.get("VENDORID");
  11.     vend_id_bigint = vend_id.toLong();
  12.     Vendor_Details = zoho.crm.getRecordById("Vendors", vend_id_bigint);
  13.     vend_directions = Vendor_Details.get("Directions");
  14.     insert into SubForm
  15.     [
  16.         Added_User = zoho.loginuser
  17.         Master_look = var1
  18.         Name = vend_name
  19.         id = vend_id
  20.         directions = vend_directions
  21.          Date_field = start_date
  22.     ]
  23. }

Many thanks