Using a field in the list to filter a lookup
- dominique.beaudin
- Posts: 49
- Joined: Tue Mar 06, 2018
Ugh. My test worked, but then when put exactly the same syntax in the "real" lookup, I get the spinning disk... no error. It is probably something silly I missed. I verified the internal names etc...
function (term, page) {
// Getting the selected country
var countryId = fd.field('ContractorID').value();
if (!countryId) {
countryId = 0;
}
// Filtering by the selected country
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby=Created desc&$filter= ContractorEquipmentID eq " + countryId + "&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "') and ContractorEquipmentID eq " + countryId + "&$top=10";
function (term, page) {
// Getting the selected country
var countryId = fd.field('ContractorID').value();
if (!countryId) {
countryId = 0;
}
// Filtering by the selected country
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby=Created desc&$filter= ContractorEquipmentID eq " + countryId + "&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "') and ContractorEquipmentID eq " + countryId + "&$top=10";
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Dominique,
In case you are working with the lookup, the expand property is necessary, as well as FieldName/Id, so it knows what to retrieve. Try this, even though it's awfully similar to the first piece of code you've posted, it still should be working:
In case you are working with the lookup, the expand property is necessary, as well as FieldName/Id, so it knows what to retrieve. Try this, even though it's awfully similar to the first piece of code you've posted, it still should be working:
Code: Select all
function (term, page) {
// Getting the selected contractor
var contractorId = fd.field('ContractorID').value();
if (!contractorId ) {
contractorId = 0;
}
// Filtering by the selected contractor
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby=Created desc&$expand=ContractorEquipmentID&$filter= ContractorEquipmentID/Id eq " + contractorId + "&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ContractorEquipmentID/Id&$orderby={LookupField}&$expand=ContractorEquipmentID&$filter=startswith({LookupField}, '" + term + "') and ContractorEquipmentID/Id eq " + contractorId + "&$top=10";
}
Cheers
- dominique.beaudin
- Posts: 49
- Joined: Tue Mar 06, 2018
I got it all working and it is BEAUTIFUL! I had an INT on one side and a String on the other. Resolving that fixed it. Thank you.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests