HI , From client script on save record, i am setti...
# suitescript
r
HI , From client script on save record, i am setting new lines on to the record. But the lines are not committing instead of that its overriding the same line. And it was working before from yesterday onwards its not working, any suggestions on this?
m
Would need to see the code to have any suggestions.
r
This is the block of code commiting new lines
Copy code
allocationSearchObj.run().each(function(result) {
                            var accountId = result.getValue('custrecord_da_all_acc');
                            console.log('accountId', accountId);
                            var weight = result.getValue('custrecord_da_dest_wght');
                            console.log('weight', weight);
                            var checkPercentage = result.getValue({
                                name: "custrecord_da_alloc_prcnt",
                                join: 'custrecord_da_all_sett'
                            });
                            console.log('checkPercentage', checkPercentage);
                            gainAndloss = result.getValue({
                                name: "custrecord206",
                                join: 'custrecord_da_all_sett'
                            });
                          
                          var lineAmount = 0;
                         if(debitAmount > 0){
                           lineAmount = debitAmount;
                         }
                          if(creditAmount > 0){
                           lineAmount = creditAmount;
                         }

                            var value;

                            if (checkPercentage == true) {
                                value = (weight / 100) * lineAmount;
                            } else {
                                value = (weight * lineAmount) / weightTotal;
                            }
                            value = Number(value).toFixed(3);
                           // totalValue = parseFloat(totalValue) + parseFloat(value);
                            context.currentRecord.selectNewLine({
                                sublistId: 'line'
                            });
                            context.currentRecord.setCurrentSublistValue({
                                sublistId: 'line',
                                fieldId: 'account',
                                value: accountId,
                                forceSyncSourcing:true
                            });
                           

                            if (credit == true) {
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'custcol_da_cr_3_decimal',
                                    value: value
                                });
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'credit',
                                    value: value
                                });
                            }else{
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'custcol_da_dr_3_decimal',
                                    value: value
                                });
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'debit',
                                    value: value
                                });
                            }
                            if (memo) {
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'memo',
                                    value: memo
                                });
                            }
                            var department = result.getValue('custrecord_da_dest_dept');
                            if (department) {
                                context.currentRecord.setCurrentSublistValue({
                                    sublistId: 'line',
                                    fieldId: 'department',
                                    value: department
                                });
                            }
                            context.currentRecord.commitLine({
                                sublistId: 'line',
                                ignoreRecalc: false
                            });

                            return true;
                        });
Please let me know, if you want to check the whole script file.
m
Everything looks fine to me in your code. Could be that something else is interfering. Usually you would receive an error if a line isn't committed, but possibly if another script or the same script was catching validateLine and not returning true it might cause it to loop without an error. But that's just a guess.
r
yup , i checked that, but there are no validate line functions in other scripts as well.
m
Workflows could operate the same way. Might need to check if there were any recent workflows created.
r
surprisingly, i have the same functionality of code on another record as well, but that also working same like this.
not committing the lines. seems any account configuration change
m
I can't think of anything that wouldn't throw an error. I hope somebody else has some ideas.
b
Use
forceSyncSourcing
on every line to avoid commiting the line before sourcing is complete
r
you mean on every setting?
i am using this on account level
b
use it every time you use setCurrentSublistValue
r
thanks @battk it works