Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.7 kB
1
Indexable
Never
fn.searchTransactionNumber= function (stTransactionType,stTransactionPrefix,stSettleDate){
            var transactionObj = search.create({
                type:'customrecord_afon_2c2p_trans_num',
                filters:[
                    ['custrecord_afon_2c2p_trans_type', 'is', stTransactionType],
                    "AND",
                    ['custrecord_afon_2c2p_trans_prefix','is',stTransactionPrefix],
                    "AND",
                    ["custrecord_afon_2c2p_trans_date","on",stSettleDate]
                ],
                columns: [
                    search.createColumn({name: "custrecord_afon_2c2p_trans_num", label: "Transaction Number"}),
                    search.createColumn({name: "internalId", sort: search.Sort.ASC, label: "Internal ID"}),
                    search.createColumn({name: "custrecord_afon_2c2p_trans_date", label: "Transaction Date"})
                ]
            });

            var searchResultCount = transactionObj.runPaged().count;
            //log.debug("transactionObj result count",searchResultCount);
            if(searchResultCount != 0){
                var intTransactionNumber = "";
                transactionObj.run().each(function(result){
                    intTransactionNumber = result.getValue('custrecord_afon_2c2p_trans_num')
                    return true;
                });
                var intAddNextNumber = Number(intTransactionNumber) + 1;
                var numPad = intAddNextNumber.toString().padStart(4,'0');

                var transactionRecord = record.create({
                    type:'customrecord_afon_2c2p_trans_num',
                })

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_type',
                    value: stTransactionType
                });

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_prefix',
                    value:stTransactionPrefix
                })

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_num',
                    value: numPad
                });

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_date',
                    value: fn.stringTodate(stSettleDate)
                });

                var transactionID = transactionRecord.save();
                //log.debug('transactionID',transactionID)

                return numPad;
            } else{

                var num = 1;
                var numPad = num.toString().padStart(4,'0');

                var transactionRecord = record.create({
                    type:'customrecord_afon_2c2p_trans_num',
                })

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_type',
                    value: stTransactionType
                });

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_prefix',
                    value:stTransactionPrefix
                })

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_num',
                    value: numPad
                });

                transactionRecord.setValue({
                    fieldId: 'custrecord_afon_2c2p_trans_date',
                    value: fn.stringTodate(stSettleDate)
                });

                var transactionID = transactionRecord.save();
                //log.debug('transactionID',transactionID)

                return numPad;

            }
        }