I have a for loop that checks over each line and i...
# suitescript
c
I have a for loop that checks over each line and if one meets criteria it will break the loop and display a message. The problem I have is that every time you click Save it's adding a new error message on top of the older one. I am trying to use message.hide(), but I am having trouble figuring out the correct placement.
c
Share your code
c
Copy code
function saveRecord(context) {
    var transaction = context.currentRecord;

    var lineCount = transaction.getLineCount({
      sublistId: "line",
    });
    
    var errorMessage = message.create({
       title: "Missing Departments",
       message: "Please Enter a Department for each line of the Journal Entry",
       type: message.Type.ERROR,
     });
  
    for (var i = 0; i < lineCount; i++) {
      var lineDepartment= transaction.getSublistText({
        sublistId: "line",
        fieldId: "department",
        line: i,
      });

      if (lineDepartment == "") {
       errorMessage.show();
       break;
      } else {
       return true;
    }
  }
}
c
Edit: wouldn't it be better to use
N/ui/dialog
instead?
🥇 1
c
Yea, now that I am looking at that is probably is
Yea, I think that works much better
thank you