Filter Related Records

Posted by Rollbase User on 11-Jul-2013 10:03

Here's an example of what I'm trying to do. I have 2 objects: Doctor Object - Doctor Name Field (Text) - Appointment Field (Lookup) Appointment Object - Doctor Name Field (Lookup - Cardinality: Many Appointment to One Doctor) - Patient Name Field (Text) - Date Field (Date) - Appointment Field (Record Name: "Patient Name — Date") I would like a Doctor view that listed all of the doctors and only the appointments that are for the current date or later. I think what I need to do is create a "Upcoming Appointments" Expression Field for upcoming appointments that loops through the appointments and add the ones with dates that are greater than or equal to 'today's' date to a new array then return the value of that array. Problem is I can't get it working. I might not even be in the right ballpark. Can someone point me in the right direction. Ideally to an example that does something similar. Much Thanks

All Replies

Posted by Admin on 11-Jul-2013 13:06

Okay, this is where I'm currently at:



I made a formula field called "Current Appointments" in my Doctor object.



The formula is:



=======



var apptDateArray = rbv_api.getRelatedFields("R72009332", {!id}, "appt_date");



/* convert current date to milliseconds */

var today = rbv_api. getCurrentDate();

var todayJava = new Date(today);

var todayMilli = todayJava.getTime();



/* loop through appointments and compare to current date */

for (var k=0; k



/* convert appt date to milliseconds */

var apptDateJava = new Date(apptDateArray[k]);

var apptDateMilli = apptDateJava.getTime();



/* compare dates */

if (apptDateMilli >= todayMilli) {

rbv_api.printArr("Current Appt = " + apptDateMilli + "\n");

}

else {

rbv_api.printArr("Past Appt = " + apptDateMilli + "\n");

}

}



=======



When debugging I get:



Past Appt = 1373000400000

Current Appt = 1373605200000



This is correct, It's the two appointment dates I m

Posted by Admin on 11-Jul-2013 15:53

Hi Jon,



Can you please let me know your rollbase login and company name, I would like to take a look at your sample application.



Thank You,

Srikanth

Progress|Rollbase Product Support Team





Posted by Admin on 11-Jul-2013 15:58

Hi Jon,



Maybe try the following formula:



======



var upcomingAppointments = rbv_api.selectQuery("SELECT name FROM appointment where appt_date >= '{!#TODAY}' and doctor = {!id}", 10);

// count number of results returned

var count = upcomingAppointments.length;



var resultString = "";



// loop through all the results

for (var i = 0; i

var apptName = upcomingAppointments[i][0]; // reference field 0 = name

if (resultString != "") resultString += "; ";

resultString += apptName;

}



return resultString;



======



This will return a string like the following: "Bobbi - 07/12/2013 04:49 PM; Joani - 07/17/2013 04:49 PM", filtered only for appointments that are today and later.



I would suggest changing the integration name for your relationships from R#### to something meaningful like "doctor" or "appointment", as I have done above.



Also, you could create a view instead of "Upcoming Appointments" which allows you to use the UI for view filters, and would display as mu

Posted by Admin on 11-Jul-2013 16:00

Is there a way to send this to you privately?

Posted by Admin on 11-Jul-2013 16:06

Sorry I thought you were asking for something else. Here's that info. Just to be clear the doctor example was just an easy to understand variation of what I'm actually trying to do.



jon@foxbot.tv

Foxbot Productions

Posted by Admin on 11-Jul-2013 16:16

I will give that a shot. Thanks!



I do have the views setup but I also need to be able to see quickly all of the doctors and their appointments. in one big spreadsheet.

Posted by Admin on 11-Jul-2013 16:26

Not working as is.



Here's the debug info:



Original Formula

======

var upcomingAppointments = rbv_api.selectQuery("SELECT name FROM appointment3 where Appointment Date >= '{!#TODAY}' and doctor = {!id}", 10);

// count number of results returned

var count = upcomingAppointments.length;



var resultString = "";



// loop through all the results

for (var i = 0; i

var apptName = upcomingAppointments[i][0]; // reference field 0 = name

if (resultString != "") resultString += "; ";

resultString += apptName;

}



return resultString;



Parsed Formula

======

001 var rbv_api = new Packages.com.rb.core.services.api.ServerSideAPI(71896001, 71897643);

002

003 function wrapper() {

004 var upcomingAppointments = rbv_api.selectQuery("SELECT name FROM appointment3 where Appointment Date >= '07/11/2013' and doctor = 73181142", 10);

005 // count number of results returned

006 var count = upcomingAppointments.length;

007

008 var resultString = "";

009

010 // loop throu

Posted by Admin on 11-Jul-2013 16:48

Hi Jon,



I don't know the name of your columns, you'll need to put in the correct names. The column "doctor" is the relationship between appointment and doctor, which is probably "R72009332" in your case.

Posted by Admin on 11-Jul-2013 17:10

Thanks Kurt! That worked beautifully.



Just wondering, what does the "10" denote in this query?



rbv_api.selectQuery("SELECT name FROM appointment3 where appt_date >= '{!#TODAY}' and doctor = {!id}", 10);



Also... Is there any way to create links that lead to the record like a typical lookup field?

Posted by Admin on 11-Jul-2013 17:12

Hey Jon,



The 10 is max number of records returned. That means will only show the next 10 appointments. You can set that to any number between 1 and 999 I believe.



You may want to refer to chapter 6 in the RollBase official documentation for information about the various API methods available, and how their parameters work. I believe there is also information there about how to create record links.



~ Kurt

Posted by Admin on 11-Jul-2013 17:20

Thanks again Kurt. I'll need to sit down and take another look. There's a lot to soak in :)

Posted by Admin on 12-Jul-2013 12:39

Hey guys, Me again.



Any ideas why the formula stopped working for me.



=====

var upcomingAppointments = rbv_api.selectQuery("SELECT name FROM appointment3 WHERE appt_date >= '{!#TODAY}' and R73229279 = {!id}", 10);



// count number of results returned

var count = upcomingAppointments.length;



var resultString = "";



// loop through all the results

for (var i = 0; i

var apptName = upcomingAppointments[i][0]; // reference field 0 = name

if (resultString != "") resultString += "; ";

resultString += apptName;

}



return resultString;



======



When trying to debug it I notice that:



'{!#TODAY}' returns this date format:

"07/12/2013"



appt_date returns something like this:

"Fri Jul 19 00:00:00 CDT 2013"



Could this have something to do with it?

Posted by Admin on 16-Jul-2013 09:10

Hi Jon,



were you able to find a solution to filter the related records? Please let me know if you'd need any assistance.



Thanks,

Corey Prak

Posted by Admin on 16-Jul-2013 09:19

I was, I had to merge what kurt showed me and my original script but I finally got it working... with url links taboot. Thanks.

Posted by Admin on 16-Jul-2013 09:28

Jon,



you're very welcome, and thanks for your quick reply. I was curious as to the specific portion of code that suddenly stopped working, but I'm glad that the formula works now.



Thanks Again,

Corey Prak

This thread is closed