Filter list with TicketID or variable

Hi,

i'm trying to filter a list with a ticker ID. I could get the TickerID wiht [TicketID] but i wasn't able to filter the list with this. Here is my Code.

fd.spRendered(function() {

 fd.control('Text1').text = '[TicketID]';
 var temp = fd.control('Text1').value;
 fd.control('Text2').text =temp;  //textfield is displaying correct ticketId  

var dt = fd.control('IST_Aufwand');
 dt.ready().then(function() {
    filterDT();
});
 dt.readonly=false;
 


function filterDT(){    
    //dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>4</Value></Eq>"; //does filter by the value 4
    dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>temp</Value></Eq>"; //doesn't work
    dt.refresh();
}
ticketForm.Render(); 

});

Hello! The Ticket ID field contains a string (not integer) therefore the temp variable is a string too. The CAML query requires an integer. You can transform it using a function parseInt().

Hello e.evseychik,

thank you for the tipp!

I tried it with the following code, but it's not working.

fd.spRendered(function() {

 fd.control('Text1').text = '[TicketID]';
 var temp = fd.control('Text1').value;
 fd.control('Text2').text =fd.control('Text1').text ;
var parse =fd.control('Text1').text;
//var int_parse = parseInt(parse);
  
  fd.control('Text2').text =parse; //does show correct ticket_id
  
var dt = fd.control('IST_Aufwand');
 dt.ready().then(function() {
    filterDT();
});
 dt.readonly=false;
 


function filterDT(){    
    dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>parseInt(parse)</Value></Eq>";  //list shows no entries
   // dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>int_parse</Value></Eq>";  //list shows no entries -> same effect as the codeline above
    dt.refresh();
}
ticketForm.Render();

});

Well, a tested it a bit and found out that [TicketID] is just a token that is replaced by an accordant value when the form is rendered. So when you assign fd.control('Text1').text to the variable, you assign just a [TicketID] string that can't be converted to an integer. You should refer to the TicketID field itself to assign its value to a variable.

  1. Add the TicketID field to the form:

  2. If you don't need it, just hide the field with a custom style:
    image

  3. Assign the value to the variable and parse integer:

var temp = parseInt(fd.field('TicketID').value);

Thanks for your reply. I tried it but it's not working.

Is this the right way to add a variable to the query?

   var temp2 = parseInt(fd.field('TicketID').value);
  1.  var filter = "<And>";
     filter += "<Eq><FieldRef Name='Test'/><Value Type='Integer'>"
     filter+= ""+temp2+"";
     filter+="</Value></Eq>";
     dt.filter
     dt.refresh();
    
  2.  or is this way correct/better?
     //dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>temp2</Value></Eq>";
    dt.refresh();

In your initial message you mentioned that this worked:

dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>4</Value></Eq>";

Then this variant also should work:

var temp = parseInt(fd.field('TicketID').value);
var dt = fd.control('IST_Aufwand');

function filterDT() {
    dt.filter = "<Eq><FieldRef Name='Test'/><Value Type='Integer'>" + temp + "</Value></Eq>";
    dt.refresh();
}

dt.ready().then(function () {
    filterDT();
});

dt.readonly = false;

ticketForm.Render();

If it doesn't, please share the full JS code that you used in the form and the screenshot that shows that the TicketID field is added to the form.