Verify that selections have been made

I have a column (CHECK) that holds boolean values of only 1 or 0. The value becomes 1 if Checked.

I want to verify that the operator has checked at least one CHECK before processing.

The code I have come up with is:

if (table2.CHECK.sum = 0){
utils.showNotification({
title: "NOTE",
description: "Please check off one or more products before clicking on this screen",
notificationType: "info",
duration: 10,
})
} else {
AwaitSaveChanges
}

Blockquote

This doesn't work.
I am including a screen capture.
Mike

Hello,

There are missing information to help with the use case.

Is the CHECK column custom column? or data from your resource (sql, api, ...)? if from resource is the column editable? Depends on answer it can have different solution.

If you just need users to make a selection of records to perform your operation, you can use multi-row select functionality of the table.

From there you can use tabl1.selectedRow.data.length to determine if any row was selected.

if (tabl1.selectedRow.data.length) {
  // has selection
} else {
  // no selection
}

This is my first time at this rodeo.


Yes, the CHECK column is editable.
I am attaching a screen shot of my button. When I click on "Add ons" I get a choice of "Prefix Icon", "Suffix Icon" or "Tool Tip".
What do I do next?
Mike

So from your image, it looks like other columns are editable as well. From your request,

I want to verify that the operator has checked at least one CHECK before processing.

whenever a user makes any changes to the data in the table...the recordUpdates property reflects with the changes.
image

To find "at least one CHECK" you can use the code below (replace the code you posted):

if (table1.recordUpdates.some(a => a.CHECK === true)) {
  // at least one has CHECK is true
  // AwaitSaveChanges
  console.log("at least one has CHECK is true")
} else {
  utils.showNotification({
    title: "NOTE",
    description: "Please check off one or more products before clicking on this screen",
    notificationType: "info",
    duration: 10,
    });
}

Iamh:
This is not exactly in the same vein but you seem to be the expert on this.

I have a table (table1) where I have made a check to select an invoice number, but I don't know how to tell java script where I made my last selection.

I am using the code below to put the selected Invoice Number (Invnbr) in Local Storage.

localStorage.setValue ('minvnumber', table1.selectedRow.data.Invnbr)

The check box is called Check01 and the value of Check01 is 1 when checked.

This gives me the first row and it does not recognize the check.

Thoughts?

Mike

Hi @mdsmith1,

My apologies for late reply, i have a solution but give me a sec to put it together. Just FYI, if you type @ follows by my id, it will notify me.

To get the last select row you can use table1.selectedRow.index[selectedRow.index.length - 1] or table1.selectedRow.data[selectedRow.data.length- 1]

In the video below, you can see the latest selection is always at the end of the array.
last selection

Lamh:
I can't quite get this to work.
I am trying to get the selected Invoice Number up to Local Storage so I am attempting to do that with

localStorage.setValue ('minvnumber', table1.selectedRow.data[selectedRow.index.data-1])

I have tried variations like:

localStorage.setValue ('minvnumber', table1.selectedRow.data[selectedRow.index.Invnbr-1])

but nothing works.

Suggestions?

Mike

@mdsmith1

You want to store the Invoice Number only? then you need to add the property name that has the invoice number. See below.

localStorage.setValue ('minvnumber', table1.selectedRow.data[selectedRow.index.data-1].invoiceNumber)

If the whole thing doesn't work, does your table has multi selection on?
image

As you can see the localStorage.setValue() is working in the video below.
last selection

I have set up my table for multiselect and with the Check Box on.

I have modified the code as below.

localStorage.setValue ('minvnumber', table1.selectedRow.data[selectedRow.index.data-1].'Invnbr')

The return value to local storage is 'null'.

I think I can send the entire table to the server and read the check box but it would be great if there was a way to get this to work.

Mike

Can you try this instead?

localStorage.setValue ('minvnumber', table1.selectedRow.data[table1.selectedRow.data.length - 1].Invnbr)

Lamh:

It worked!
Thank you so much.
This will really speed up my screens for this.
Thank you again.
Mike

1 Like

Awesome, glad it worked.