Autofill Function working on Single Form Entry but not Multiple List

Process: 

Takes order and item information and updates selected items. 

When taking order and item information I want both the order info and item info to display without all of the info being stored. The only info that will be stored is the updated information to items (in a separate Business Object to the original item info). 

Ie, the form will read Order ID and display the Customer Name and Sale Rep info. The user can then add containers in the form to fill in Item ID which will display the Item Name and Customer Requested Delivery Date. The user then manually completes an Updated Delivery Date and Comment field. 

The output info is only the Item ID, Updated Delivery Date and Comment. I am confident that this is easily solved using formOuput JSON. All of the variables that I wish to be referenced in the autofill js functions are in formInput. 

 


What I have working: 

An autofill field and function for the order information: 

function fillOrder(orderList, updateDDInput, orderId) {
  for(var i=0; i < orderList.length; i++) {
    if(orderList[i].orderID== orderID) {
      updateDDInput.customerName = orderList[i].customerName;
      updateDDInput.saleRep = orderList[i].saleRep;
      updateDDInput.order_PID = orderList[i].persistenceId;
    }
  return "";
}}

 

JS Var: fillOrder

return fillOrder($data.orderList, $data.formInput.updateDDInput, $data.orderID);

 

API Link: objectList

../API/bdm/businessData/qur.model.Order?&q=findDESC&p=0&c=1000

Using this I am able to enter an Order ID and display the Customer Name and Sale Rep.

 

 


What is not working: 

I am trying to develop another function which allows me to also fill Item data on the same form, within containers that the user can add and remove. 

I am unsure where to reference 'item' in the JS for the autofill function to be successful. You can expect that JS Var and API link are similar for Items:  (itemInfo is updateDDInput.itemInfo; itemList is API link, j is the $item from form)

function fillItem(itemList, itemInfo, itemID, j) {
  for(var i=0; i < itemList.length; i++) {
    if(itemList[i].itemID == itemID[j]) {
      itemInfo[j].etdP = itemList[i].etdP;
      itemInfo[j].itemInformationP_PID = itemList[i].persistenceId;
      itemInfo[j].itemNameP = itemList[i].itemNameP;
    }
  return "";
}}

 

However, this does not autofill into the container based on ItemID in the manner that I hoped. 

How can I correctly reference each container (using $item?) in the JS for this feature to work...? 

Any help is greatly appreciated.