Put Date Range into URL

Andrew Bettcher
Kilo Sage

Hi,

I've got a UI that pops up on a button click. It asks the user for two values which are "From Date" and "To Date". When the user clicks OK, I want to redirect them to a list of records that were created between the two dates.

The URL I'm getting now looks like this (Just using the "From Date" value at the moment to get it working)

/u_overtime_claim_list.do?sysparm_query=created>01/06/2022

I filtered on the list view and the URL looked like this:

/nav_to.do?uri=%2Fu_overtime_claim_list.do%3Fsysparm_query%3Dsys_created_on%253Ejavascript:gs.dateGenerate(%25272022-06-01%2527%252C%252723:59:59%2527)%26sysparm_first_row%3D1%26sysparm_view%3D

 

The question is then, how do I get from the former to the latter OR, is there an easier way of doing this?

 

Here is the client script from the UI Page:

function onCancel() {
	GlideDialogWindow.get().destroy();
    sendEvent('modal:close');
	return false;
}


function onOK() {
   //Gets called if the 'OK' dialog button is clicked
	
	var fromDateCheck = gel('from_date').value;

	var toDateCheck = gel('to_date').value;
	

           if (fromDateCheck == '' || toDateCheck =='') {

                   alert("Please complete all fields or click cancel to exit");

                   return false;
   }

	var fromDate = document.getElementById("from_date").value;
	var toDate = document.getElementById("to_date").value;
	
	GlideDialogWindow.get().destroy();    //Close the dialog window
	var url = "/u_overtime_claim_list.do?sysparm_query=created>" + fromDate;
	alert(url);
	//window.open(url);
	action.setRedirectURL(current);
	//return true;
	

	
}

N.B. Not sure how to generate the actual page (Redirect or Open). Not got that far yet....

1 ACCEPTED SOLUTION

Andrew Bettcher
Kilo Sage

I appear to have done this:

 

var url = "/u_overtime_claim_list.do?sysparm_query=sys_created_onBETWEEN" + fromDate + "%40" + toDate;

 

That opens a new page with a list where the filter looks like this:

find_real_file.png

Note that, for some reason, the last date has the day and month in a different spot (I selected the 11th June). No idea why so will mark this post as complete and create a new one for that issue.

View solution in original post

1 REPLY 1

Andrew Bettcher
Kilo Sage

I appear to have done this:

 

var url = "/u_overtime_claim_list.do?sysparm_query=sys_created_onBETWEEN" + fromDate + "%40" + toDate;

 

That opens a new page with a list where the filter looks like this:

find_real_file.png

Note that, for some reason, the last date has the day and month in a different spot (I selected the 11th June). No idea why so will mark this post as complete and create a new one for that issue.