Error after update

Hello there,

we have some table which is generating new ID from multiple sources and today it has stopped working.

   // place your code here
       // When record is new
    if (doo.model.ver == -1) {
        //Automatic ID function with table NumericalSeries
        // get data where [Agenda == Inventory and Active == true]
        let resultNumericalSeries = await doo.table.getData('numericalSeries',
            {
                filter: [
                    { field: "NUMS_agenda", operator: "in", value: "Inventory" },
                    { field: "NUMS_active", operator: "eq", value: true }
                ], filterOperator: "and"
            }
        );

        // if some record exists
        if (resultNumericalSeries.data.length > 0) {
            // save value of field Prefix to variable
            var nsPrefix = resultNumericalSeries.data[0].fields.NUMS_prefix;
            // save value of field Number to variable
            var nsNumber = resultNumericalSeries.data[0].fields.NUMS_number;
            // save Number length (summ of characters) to variable
            var Length = nsNumber.length;
            var Prefix = nsPrefix
        }
        // else default values
        else {
            var Length = 2;
            var Prefix = "undefined";
        }
        
        // get the one last record of table InventoryEvidence where Year contains Prefix value
        const resultEvidence = await doo.table.getData('inventoryEvidence',
            { filter: [{ field: "SE_year", operator: "contains", value: Prefix }], limit: 1 }
        );
        
        // if some record exists 
        if (resultEvidence.data.length > 0) {
            // save value of field ContractNo to variable
            var lastID = resultEvidence.data[0].fields.SE_evidence;
            // save value of Prefix to new variable 
            var lastPrefix = lastID.substr(0, lastID.length - Length);
            // save value of Number to new variable 
            var lastNumber = parseInt(lastID.substr(lastID.length - Length));
        }
        // if records doesn't exist but there is new active record in table Numerical series
        else if (Prefix != "undefined") {
            var lastPrefix = Prefix;
            var lastNumber = 0;
        }
        // else start from 0
        else {
            var lastNumber = 0;
        }

        // adding 1 to last number
        var nextNumber = lastNumber + 1;
        // convert Number to String
        var paddingNumber = nextNumber + '';

        // if length of number is less than Length value then add "0"
        while (paddingNumber.length < Length) {
            paddingNumber = "0" + paddingNumber;
        }

        // save new ID to variable
        var newID = paddingNumber;
        // set value this value into field
        doo.model.SE_evidence.setValue(newID);
    }

Custom user Javascript error (check the console for more details): Cannot read properties of undefined (reading ‘substr’)

Can you help me solve this out? Thanks.

Hi,

does this problem still occur? for a quicker solution, please contact support@tabidoo.cloud.

With Regards,

Filip

Hello Filip,

yes, still same:

Custom user Javascript error (check the console for more details): Cannot read properties of undefined (reading ‘substr’)

Hi Thomas,

would you mind writing an inquiry to support@tabidoo.cloud? Most likely you are not getting all the data into the script.