The goal is to implement a work around to filtering Child List with lookup field where all items without lookup field set are shown in any new Parent Form.
I have followed the article about filtering Child List with CAML, but unfortunately it doesn't work.
Explanation:
My Child List Form has 3 fields "DocumentType", "RequestNumber" - which is lookup and "RequestNumberTMP" where I write Parents requestNumber - so even if I add an document to child list and close parent without saving I will be able to clean child list with event receiver (at night on daily basis) or so.
My code:
function filterAtt(){
var attfilter = "<Eq><FieldRef Name='RequestNumberTMP'/><Value Type='Text'>" + rrnumber +"</Value></Eq>";
dt.filter = attfilter;
dt.refresh();
}
fd.spRendered(function () {
rrnumber = generateIdentifier(); //this returns custom ID = text
fd.field('RequestNumber').value = rrnumber; //this is later read in Child form and child's field RequestNumberTMP is set
fd.field('RequestNumber').disabled;//so user can not change it.
var dt = fd.control('Attachment');
dt.ready(function() {
filterAtt();
});
}
If you want to set the variable value like this, the function must return value. Otherwise the variable is empty and you see the item with the empty field:
function generateIdentifier() {
var now = new Date();
var rnumber = "PZ_" + now.getFullYear() + ("0" + (now.getMonth() + 1)).slice(-2) + ("0" + now.getDate()).slice(-2) + "_" + ("0" + now.getHours()).slice(-2) + ("0" + now.getMinutes()).slice(-2) + ("0" + now.getSeconds()).slice(-2);
//function returns value
return rnumber;
};
Also, if you want to disable the field use this code:
Hi @mnikitina,
Thank you for this advise. I applied your suggestions but still in the same place. Child list is not filtered.
I found one interesting fact in my filterAtt() in dt.ready() function. It doesn't executes. I placed some console.log commands inside the filterAtt() so you can see them working but the one in dt.ready() doesn't executes.
function filterAtt(rrnumber){
console.log('In filterAtt:');
console.log(rrnumber);
var dt = fd.control('Zalaczniki');
if (fd.control('Zalaczniki')){console.log('Control exists!');};
dt.ready(function() {
var attfilter = "<Eq><FieldRef Name='RequestNumberTMP'/><Value Type='Text'>" + rrnumber +"</Value></Eq>";
console.log(attfilter); //this line doesdn't return value of attfilter
dt.filter = attfilter;
dt.refresh();
});
}
function filterAtt(rrnumber){
console.log('In filterAtt:');
console.log(rrnumber);
var dt = fd.control('Zalaczniki');
if (dt){console.log('Control exists!');};
dt.ready().then(function(dt) { //updated line
console.log('In dt.ready');
var attfilter = '<Eq><FieldRef Name=\'RequestNumberTMP\'/><Value Type=\'Text\'>' + rrnumber +'</Value></Eq>';
console.log(attfilter); //this line doesdn't return value of attfilter
dt.filter = attfilter;
dt.refresh();
});
console.log('End of filterAtt function - out of dt.ready()');
}