Unable to Filter a Filtered Result

I am trying to edit a record using session variables. There are TWO conditions passed into this form: RegDash and RegDate. Both of these values must be used to edit the correct record.

I used the following Forum post as a guide:

However, The filter DOES NOT WORK, it gets the wrong item???

Here is pic of my code:

Thanks,
JD

I rewrote the code to use wixDataquery instead of a filter:

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import {local, session} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {
let formType = session.getItem(“Edit#Sel”);
let regDash = session.getItem(“CarId”);
let regDate = session.getItem(“eDate”);
// EDIT THE RECORD PASSED BY SESSION
if (formType === “Edit”){
console.log("regDash ",regDash)
console.log("redDate ",regDate)

wixData.query(‘CV-History-Registry’)
.eq(“dash_no”, regDash)
.eq(“entry_date”, regDate)
.find()
.then(res => {
$w(“#input1”).value = res.dash_no;
$w(“#datePicker1”).value = res.entry_date;
$w(“#textBox1”).value = res.content;
session.clear();
});
}
else {
$w(“#button3”).label = “Submit”;
}
});

END CODE =====================================================
Now it runs without errors BUT returns the wrong item???


It invokes the input / update FORM with NOTHING on it… Errors all three fields!

You can check this example if you want

Thanks but I am not understanding your code. What I need is a simple AND condition on a filter! I can’t believe it is this difficult!

Okay cool
Then use it like this

filter = filter.eq("dash_no" , regDash).eq("regDate" , regDate);
$w("#dataset1").setFilter(filter)

RunTIme error in Chrome Developer Tools:


NEW REVSIED CODE:

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import {local, session} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {
let formType = session.getItem(“Edit#Sel”);
let regDash = session.getItem(“CarId”);
let regDate = session.getItem(“eDate”);

// EDIT THE RECORD PASSED BY SESSION
if (formType === “Edit”){
var filter = filter.eq(“dash_no” , regDash).eq(“entry_date” , regDate);
$w(“#dataset1”).setFilter(filter)
}
else {
$w(“#button3”).label = “Submit”;
}
session.clear();
});

Is it possibly because the regDate is a DATE/TIME fields?

Hey cwvega,
Sorry i didn’t get the notification.
Use it like this

  if(formType === "Edit") {
          var filter = wixData.filter().eq("dash_no" , regDash).eq("entry_date" , regDate);
       $w("#dataset1").setFilter(filter)   }  
       else {  
        $w("#button3").label = "Submit"; 
           } 
          session.clear(); 
         }); 

Not working. I selected record 125 as shown in Developer console… Form shows 1st record all fields error’d out.???

bumping for you

Still Fighthing with this.
Here is the scenario,

The page list-registry-histories LISTS all the history records. They are stored by Dash#, Date/Time. When database is ready, I am storing the date as retrieved in a session variable. Console log shows it correctly in LONG format. For example:

Thu Aug 02 2018

I am then converting to simple Date without the TIME(GMT) mumbo jumbo as you call it. Record is displaying as I wish. The display also contains a button click event that loads THIS page and using the session variables dash_no and entry_date. I have also console logged the session variable from the GET and it is same as what was sent. BUT, it displays the WRONG record. I am thinking that INTERNALLY the date is stored differently…as you suggested SO…

I created an additional text field in the repeater called origDate that is connect the same database entry_date. Then onRepeaterReady, I HIDE this text field. Also, console logged this extra field. It is getting preserved as the copy is what gets modified for actual display in the repeater.

Here is the RunTime log. It clearly shows the List program is setting session variable properly, and on the Update click the new page is also properly getting the right session variable valus.

Time removed from Date/Time Stamp: New Date Thu Aug 02 2018
wixcode-worker.js:17 CarId: 2716
wixcode-worker.js:17 eDate: Fri Aug 03 2018 00:00:00 GMT-0400 (Eastern Daylight Time)
console.js:35 Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
console.js:35 Loading the code for the Update Registry History page. To debug this code, open wqukw.js in Developer Tools.
console.js:35 CarId: 2716
console.js:35 eDate: Fri Aug 03 2018 00:00:00 GMT-0400 (Eastern Daylight Time)

yet, the displayed input form has the WRONG record and all three fields are unselected WHITE???


I am going to revert to the wixDataQuery method I tried earlier…just to see what happens…

Same Danged Problem!!!

FYI - When ONLY one entry for a given dash_no is present you don’t get the white screen, but the it shows the FIRST record on the form. If more than one entry but each with different date you get the White Input Form. Therefore, the FILTER is DEFINITELY NOT WORKING.

Problem solved by hiring a Wix Consultant.

Hi, glad it worked out :). If possible, share the solution in case other people encounter the same issue.
Thanks!

1 Like

Absolutely NOT. I had to PAY a consultant to fix this for me because no one from WIX would help me!