How to hide Submit button on a catalog item until a Multirow Variables set vriable has an entry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
48m ago
Hi All
I have a client script that I use on standard Variable set that hides the submit button until all the variables are entered.
How do I achieve this with a Multirow variable set?
I need to stop people submitting a ticket by mistake without entering any details
Thankyou in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
19m ago
Hi @jonathangilbert ,
To hide the Submit button until a Multirow Variable Set (MRVS) has at least one entry, you need to use a Catalog Client Script that checks the MRVS row count and toggles the visibility of the Submit button accordingly.
Step-by-Step Solution:
- Use a Catalog Client Script (Type: onLoad and onChange)
Create a Catalog Client Script on the catalog item with the following configuration:
- Type: onLoad and onChange
- Applies to: The MRVS variable
- Script:
function toggleSubmitButton() {
var rowCount = g_form.getValue('your_mrvs_variable').split(',').filter(Boolean).length;
g_form.setSubmitButtonVisible(rowCount > 0);
}
toggleSubmitButton();
- Replace 'your_mrvs_variable' with the actual name of your MRVS variable.
2. Handle Dynamic Updates with onChange
To ensure the Submit button updates when rows are added or removed, create an additional onChange Catalog Client Script on the MRVS variable:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
toggleSubmitButton();
}
This ensures the visibility of the Submit button updates dynamically as users interact with the MRVS.
Best Practices:
- Avoid DOM manipulation: Use g_form.setSubmitButtonVisible() instead of hiding buttons via document.getElementById() or jQuery.
- Use split(',') cautiously: This assumes the MRVS stores row IDs as a comma-separated string. If your setup differs, you may need to use Glide APIs or a GlideAjax call to count rows.
- Consider mandatory fields inside MRVS: If you want to ensure valid entries, you may need to validate required fields within each row before enabling Submit.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Best,
Anupam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10m ago - last edited 6m ago
For a 100% human reply, you can get the value of the MRVS using g_form.getValue('mrvs_internal_name'). Log this to see what you get - I've seen an empty MRVS returned as '[]' in some cases, so I usually check the length before proceeding.
var mrvs = g_form.getValue('employees');
if (mrvs.length > 2) { //MRVS is not empty
....
You can also use this to return false in an onSubmit script if hiding the Submit button is problematic.
