Hi all! I've got a suitelet that has a sublist and...
# suitescript
k
Hi all! I've got a suitelet that has a sublist and a list of filters. I have two buttons, submit and refresh. I want refresh to reload the sublist filtered by the user input and submit to process the filtered sublist. I've got the submit button working (it's just a submit), but how can I get the refresh button to "get" the suitelet with the field values selected?
d
i actually did this recently myself. someone else might chime in with a better way but what i did was create a client script that i linked to from the suitelet w/
form.clientScriptModulePath = './pathToScript/script.js
then the button, which also is being created in the suitelet just calls a function, which i'm exporting via the client script:
form.addButton({
'id': 'custpage_filter_results',
'label': 'Filter Search Results',
'functionName': 'handleSearch'
});
then in my handleSearch() function in the client script i'm performing the actual logic of packing up whatever data i need from the filtered input and reloading the page with them:
//set up URL parameters to pass to search on reload
let params = new URLSearchParams(window.location.search);
// Update or add parameters
params.set('custpage_xxxxxx', rec.getValue({ fieldId: 'custpage_vendor_filter' }) || '');
params.set('custpage_xxxxx', rec.getValue({ fieldId: 'custpage_trandate_filter' }) || '');
params.set('custpagexxxxx', rec.getValue({ fieldId: 'custpage_date_range_start_filter' }) || '');
params.set('custpage_xxx', rec.getValue({ fieldId: 'custpage_date_range_end_filter' }) || '');
params.set('custpage_xxxx', rec.getValue({ fieldId: 'custpage_subsidiary_filter' }) || '');
// Build new URL and reload
let url = window.location.pathname + '?' + params.toString();
window.location.href = url;
then finally back in the suitelet, on GET i'm getting those, pushing to search filters as needed (maybe not applicable for your ask, i don't know) and setting the suitelet field values:
let dateRangeStart = params.custpage_date_range_start_filter;
let dateRangeEnd = params.custpage_date_range_end_filter;
if (dateRangeStart && dateRangeEnd) {
filter.push('AND', ['trandate', 'within', formatDate(dateRangeStart), formatDate(dateRangeEnd)]);
}
if (dateRangeStart) form.getField({ id: 'custpage_date_range_start_filter' }).defaultValue = formatDate(dateRangeStart);
if (dateRangeEnd) form.getField({ id: 'custpage_date_range_end_filter' }).defaultValue = formatDate(dateRangeEnd);
that's maybe a little convoluted but it worked for my client's needs. definitely a learning experience
💯 1
k
This is very similar to the solution I was in the process of writing myself!
🕺 1
Now to come up with valid search filter operators for inventorycount record field values 😅
😆 1
a
literally also doing this right now... you should probably add a step on the form creation process in the GET to set a default value in the field for the filter you're applying from the param value. that way the search results will reflect the visibly set filters on the form when you do the window.location refreshes you'll lose them otherwise so your results will have the filters applied but they'll be no visual indication of what those filters are.
👍 1
b
Sublist.addRefreshButton is the exotic option that requires you to use something like cookies to pass state. Its primary advantage is that it does not reload the page
😮 1
k
yeah I found that but couldn't figure out how to pass filters to it
This works but refreshes the page.
Copy code
var suiteletUrl = url.resolveScript({
            scriptId: 'customscript_mvn_inventorycount_sl',
            deploymentId: 1,
            params: params
        });
        window.location.href = suiteletUrl;
b
the refresh button adds a button that does another get to the suitelet, and your suitelet is supposed to respond with another form that has the new sublist that you wish to display. There is no documented way to pass filters to it, which leaves you with things like cookies
k
Hmm ok I'll look into it
Isn't there a session object in suitescript somewhere?
yeah this might work
b
now look on the set side, and pay attention to the supported script types
its still usuable, but not as convenient as you think it is
k
oh interesting
so the client script can't actually set it at all
Why doesn't Slack have a reply to post the way Discord does? @Anthony OConnor
you should probably add a step on the form creation process in the GET to set a default value in the field for the filter you're applying from the param value.
This is exactly what I'm doing
Copy code
const filterItemFld = form.addField({
    id: 'custpage_filter_item',
    type: serverWidget.FieldType.TEXT,
    label: 'Item Number',
    container: grpFiltersId
  });
  filterItemFld.defaultValue = params.custpage_filter_item || '';
And then later on in the sublist section
Copy code
// Item
    if (params['custpage_filter_item']) {
      filters.push('AND');
      filters.push(['item', 'is', params['custpage_filter_item']]);
    }
👍 2
a
it does... it starts a thread but we're already in a thread and you can't nest them 😛
🫠 1
k
No I mean in discord you can reply to a post within in a thread and it adds a little snippet of the post you're replying to which is itself a link back to that post and tags the user
very handy for long threads
d
^^ I do really love that about discord. Google chat does that as well
a
> very handy for long threads you can just manually do it using the quote and copy paste, not to be a slack apologist or anything 😄 I've only ever experienced that in whatsapp, and i honestly find if very annoying and it clutters the main conversation
😆 2