Filter by caml DataTable

Good day,
Can i filter by caml in dataTable and then refresh it ? i need to find a title and if it exists alert, if no to write in table and save.
I tried as for list and library control filter, but have an error on dt.resfresh();

Hello @ixxxl,

Could you please provide more details on what you are trying to design.

What control are you using? List or Library or DataTable?
Do you need to check if specific record exist and if not, create a new record? When do you need to perform the action? Under what conditions or specific action?

@mnikitina
it is DataTable. Yes a i need to verify if column1 exists record with specific words, and close form if exists or create new record if not.
This action i put on press button. Condition must be if column1 have filtered information or not.
it is like for list and library

var filter = "<And>"
//add existing filter value
filter += fd.control('DataTable2').filter;
//add your own filtering conditions
filter +=  "<Eq><FieldRef Name='Eveniment'/><Value Type='Text'>Cererea a fost preluată</Value></Eq>";
filter += "</And>"
//filter list or library control   
fd.control('DataTable2').filter = filter;
//fd.control('DataTable2').refresh();

function SaveOrClose() {
//close the form if there are records in the list or library control
 //&&  fd.field('Statutul_x0020_Cererii').value != 'Supervizor'
if (fd.control('DataTable2').widget.dataItems().length > 0) {
alert(fd.control('DataTable2').widget.dataItems().length)
    //  Close form and display Alert 
    fd.spClosed(function() {
        alert("Cererea a fost deja preluată");
    });
  
    return fd.close();
} else {
    
	sp.web.lists.getByTitle("TestHelp").items.select("Statutul_x0020_Cererii").filter("ID eq '" + fd.field('ID').value + "'").get().then(function (items) {
    if (items.length > 0) {
        if (items[0].Statutul_x0020_Cererii == null || items[0].Statutul_x0020_Cererii == fd.field('Statutul_x0020_Cererii').value) {
            fd.spBeforeSave(function(spForm) {
                fd.field('Statutul_x0020_Cererii').value = 'Preluată';
				var user=_spPageContextInfo.userDisplayName
var Event = 'Cererea a fost preluată'
var Coment=fd.field('ComentariuRenunt').value
//_spPageContextInfo.userDisplayName;
    var today= new Date();
    var time= today.getHours()+ ":"+ today.getMinutes()
	 var date = today.getDate()+"."+today.getMonth()+"."+today.getFullYear()
	if(today.getMinutes() < 10){
var time = today.getHours() + ':0' + today.getMinutes();
}
   
	if(today.getMonth() < 10){
var date = today.getDate()+".0"+today.getMonth()+"."+today.getFullYear()
}
	
    var dateTime = date+' '+time;
      records = [{
        Column1: dateTime,
        Column2: user,
        Column3: Coment,
        Column4: Event
    }]
    
    records.forEach(function(record,index) {
        fd.control('DataTable2').value.push(record)
    })
                return fd._vue.$nextTick();
            });
          return fd.save();
        } else {
            alert("Sesiunea curentă a expirat redeschideți cererea din nou !!!");
         //   return fd.close();
        } //else
    } //if
});
    

but for data Table filter doesn't work

Hello @ixxxl,

You can check if specific record exist or not using the code:

var records = fd.control('DataTable1').value;
var recordExict = false;

records.forEach(function(r){
    //check if record exist
    if(r.Column1 == 'Test Record'){
        recordExist = true;
    }
})

if(recordExist){
   //save and close the form
    fd.save();
}
else{
    //create record
}
1 Like

@mnikitina
Thank you!!