Filter List or Library Control by ItemId

Good Afternoon,

Sorry about all the questions today, I am trying to filter a List Library Control by the Item Id of the opened item rather than a field value. I have the filtering working from the title field but there could be occassions where items have duplicate titles, filtering by Id will ensure I only ever return the correct items.

My working code is: -

var dt0 = fd.control('SPDataTable0');
if (dt0.widget) {   
    filterDT0();
} else {
    dt0.$on('ready', function() {
        filterDT0();
    });
}
function filterDT0(){
    dt0.filter = "<Eq><FieldRef Name='Quote_x0020_Number_x003a_Referen'/><Value Type='Text'>" + quoteReference + "</Value></Eq>";
}

I have tried the below to filter by Id but it doesn’t work: -

 var dt0 = fd.control('SPDataTable0');
if (dt0.widget) {
    filterDT0();
} else {
    dt0.$on('ready', function() {
        filterDT0();
    });
}
function filterDT0(){
    dt0.filter = "<Eq><FieldRef Name='Quote_x0020_Number_x003a_ReferenId'/><Value Type='Text'>" + ItemId + "</Value></Eq>";
}

And: -

var dt0 = fd.control('SPDataTable0');
if (dt0.widget) {
    filterDT0();
} else {
    dt0.$on('ready', function() {
        filterDT0();
    });
}
function filterDT0(){
    dt0.filter = "<Eq><FieldRef Name='Quote_x0020_Number_x003a_ReferenId'/><Value Type='Integer'>" + ItemId + "</Value></Eq>";
}

Thanks again…

Dear @Tony_Duke,
Can you tell me more about these Quote_x0020_Number_x003a_Referen and Quote_x0020_Number_x003a_ReferenId fields? Are these Lookup fields or something else? If you want to filter by ID, it’s easy like this:

function filterDT(){
    dt.filter = "<Contains><FieldRef Name='ID'/><Value Type='Text'>" + ItemId + "</Value></Contains>";
}

But you are trying to filter by some other field it seems, and that could be causing an issue, so I need to learn more about it in order to help.

Hi Nikita,

Yes the Quote_x0020_Number_x003a_Referen field is a Lookup back to the Parent List (i.e. the list in which the item resides that we have open)
Basically the functionality I am trying to recreate is as per the attached image from the DataSource of a Related Item Control within Forms Designer.
Quote_x0020_Number_x003a_Referen is the internal name of the “Solutions Quote Reference” field

Capture

Thanks