This topic contains 9 replies, has 0 voices, and was last updated by Shanthi Vedulla 8 years ago.
-
AuthorPosts
-
October 19, 2016 at 11:06 am #1665
karennHi All,
I may be making this harder than it really is, I hope so.
I am trying to create a portlet or suitelet that will allow the user to enter a date range and then the script will use that date range when calling a saved search and then using the data it will build an HTML table displaying the results.
Now, if I just hardcode some dates I can call the search and build the HTML table and it displays great, no problem. If we always wanted to just so the current month this would be great, but sometimes they need to see the previous month or some other previous month.
I am not seeing or understanding how I can do this. Any help would be appreciated.
Thanks!
Karen
This is a cached copy. Click here to see the original post. -
October 19, 2016 at 11:47 am #1666
al3xiconI’m sure you’ve thought of this already if you are to the point where you are considering scripting, but can you just use a saved search with a date field as the available filter?
-
October 19, 2016 at 11:53 am #1667
karennYeah the problem is this actually requires 2 searches to also get date for the previous year for the date range (ie this month compare to same moth last year) and then some calculations are done on all that data. What is actually being displayed is not just search data and searches and reports just can;t do what we need this to do unfortunately.
-
October 19, 2016 at 1:21 pm #1668
david.smithCreate a suitelet as a form with the date fields, etc. The user using the submit button will post those dates back to your suitelet as parameters. Dynamically add those parameters to your search to display the results.
If you want to use a saved search you can get creative with the search URL and just add the dates to the search url in a new window.
-
October 19, 2016 at 1:32 pm #1669
karennHi David
Been trying to wrap my head around this solution for a while. So, would there have to be a userevent script to grab the dates and add them as parameters? But if so how is this script associated with the form so it is executed on submit. I have seen if you add a non-submit button where you can associated it with a script but not submit buttons,
Thanks,
Karen
-
October 19, 2016 at 2:07 pm #1670
david.smithSS1 or SS2?
When you do a suitelet and create a form you can add a submit button. Any fields you add to the form are sent as POST parameters with the vaules back to the suitelet when the user hits submit. I’m working with one now so here is a code sample using SS2.0.
Code:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define([ ‘N/search’ ,’N/ui/serverWidget’],
/**
* @param {search}
* search
*/
function(search, ui) {/**
* Definition of the Suitelet script trigger point.
*
* @param {Object}
* context
* @param {ServerRequest}
* context.request – Encapsulation of the incoming request
* @param {ServerResponse}
* context.response – Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
try {
var request = context.request;
var response = context.response;log.debug(‘context’,context);
if (request.method === ‘GET’) {
var form = ui.createForm({
title: ‘Search w Dates’
});
//form.clientScriptFileId = 1077203;
//form.clientScriptModulePath = “SuiteScripts/SWK/some.js”;var startDate = form.addField({
id: ‘custpage_startdate’,
type: ui.FieldType.DATE,
label: ‘Starting Date’,
source: null
});
var endDate = form.addField({
id: ‘custpage_enddate’,
type: ui.FieldType.DATE,
label: ‘Ending Date’,
source: null
});
var fltrBtnLabel = ‘Load Data from Set Filters’;
form.addSubmitButton({
label : fltrBtnLabel
});response.writePage(form);
return;
/******************************* END HTML **************************/
}/**********POST**************/
var sd = request.parameters.custpage_startdate || null;
var ed = request.parameters.custpage_enddate || null;
return;} catch(e){
log.error(‘date suitelet’, e.message)
return;
}Post response looks like this.
-
October 19, 2016 at 2:15 pm #1671
karennDavid, you are AWESOME! I knew there was a way but I just could not seem to get my head around it. I will give this a try and see what happens. Thanks!
-
October 20, 2016 at 12:07 am #1672
chanarbonHi @karenn,
Adding to the details provided by David, it is already on the Suitelet’s context itself very similar to 1.0. In 1.0 you get it from the request parameter of your Suitelet function via request.getParameter. In SuiteScript 2.0, pretty much is is just context.request.parameters.parameters.. In the case shown by David, the Suitelet that he created used ‘custpage_startdate’ and it is visible directly in the parameters object
-
October 20, 2016 at 6:33 am #1673
karennThanks David. I moved the retrieval of the parameters to the beginning and then always rebuild the HTML based on the dates provided if any and it is working like a champ. Knew it could not be as hard as I was making it out to be.
Thanks all!
-
October 21, 2016 at 11:26 am #1674
Shanthi VedullaHi everyone,
I have been following this thread for past 2 days but I was trying different options before I reached out to you.
I am also trying to script something very similar.
But the input fields are 2 dates and 3 select fields (need to perform searches in the code). These should be available in a portlet.
When the user selects the values for these fields and click submit, it should call a Suitelet and perform more Searches in it and display the content back in the same portlet. The values in the selected fields on the portlet should be retained. is there a way to do this. I have been trying various options. If I do an iFrame, the select fields do not work correctly as their values are dynamically retrieved. I have a code similar to the one shown above but in SuiteScript 1.0.
I have also tried to dynamically create the fields from the Suitelet itself, like suggested above. But this Suitelet has to be triggered on the load of Portlet.
Is there a way to trigger the Suitelet from a Portlet and display the results in the same Portlet?
Thank You.
-
AuthorPosts
You must be logged in to reply to this topic.