Hi, 

I have some hard times trying to iterate an array of object and insert/display the values one by one on this object detail named Product in Receive

 

and here is a chunk of the code:

var splitResult = decodedText
          .split("*")
          .filter((item) => item.trim() !== "");
        var doNumber = splitResult[0];
        var prodDataObj = [];
        var slocCode = doNumber.split("/")[1];
 
        for (let i = 1; i < splitResult.length; i++) {
          var prodDataSplit = splitResult[i].split("/");
          var productName = "";
          var materialcode = prodDataSplit[1] || "";
 
          if (materialcode) {
            productName = await new Promise((resolve) => {
              Terrasoft.productByMaterialCode(materialcode, (productData) => {
                if (productData && productData.Name) {
                  resolve(productData?.Name || "");
                }
              });
            });
          }
          prodDataObj.push({
            Line: prodDataSplit[0] || 0, //line number
            MaterialCode: prodDataSplit[1] || "", //mat code
            ProductName: productName,
            Quantity: prodDataSplit[2] || 0, //quantity
            UoM: prodDataSplit[3] || "", //uom
          });
        }
prodDataObj.forEach((data) => {
          const newRecord = Ext.create("Terrasoft.BaseModel", {
            modelName: "UsrEntity_93626c0",
          });
 
          newRecord.set("UsrSKUName", data.ProductName, true);
          newRecord.set("UsrQty", data.Quantity, true);
 
          Terrasoft.getUom(data.UoM, (record) => {
            newRecord.set("UsrUoM", record, true);
          });
 
          newRecord.save({
            isCancelable: false, 
            success: function (savedRecord) {
 
              const pageController = Terrasoft.PageNavigator.getLastPageController();
              pageController.refreshDirtyData();
            },
            failure: function (error) {
              console.error("Failed to create record:", error);
            },
          });
        });

i tried to iterate using forEach but when i use newRecord.save, some weird error appears, this is one of them: 

Error in Success callbackId: TSQueryExecutorPlugin1965367711 : TypeError: Cannot read properties of undefined (reading 'rule')

 

I would greatly appreciate any assistance or guidance in resolving this issue.
Thank you.

 

Like 1

Like

1 comments

Hello,
In this situation, only the full debug of the set code can tell what exactly went wrong. Based on the code alone it is impossible to tell where is the issue in it.
The error "TypeError: Cannot read properties of undefined (reading 'rule')" doesn't tell much easier, with it we can only tell that at some point the system didn't receive a correct parameter or didn't receive anything at all, either way, a debug is still needed.

Show all comments