How to have lookup content filtered by CAML?
Nope , still getting "No matches found"
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby=Created desc&$expand=ParentCategory/Id&$filter=ParentCategory/Id eq null &$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby={LookupField}&$expand=ParentCategory/Id&$filter=startswith({LookupField}, '" + term + "') and ParentCategory/Id eq null &$top=10";
}
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby=Created desc&$expand=ParentCategory/Id&$filter=ParentCategory/Id eq null &$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby={LookupField}&$expand=ParentCategory/Id&$filter=startswith({LookupField}, '" + term + "') and ParentCategory/Id eq null &$top=10";
}
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Are you sure you have items in the Source List with empty ParentCategory field?
I've tested this code prior to sending it and have only replaced the field name to the one you've provided. In order to test that we are calling correct field in the correct list, try to replace eq with ne (not equal). It should be something like this and it should return all values where ParentCategory is not empty.
I've tested this code prior to sending it and have only replaced the field name to the one you've provided. In order to test that we are calling correct field in the correct list, try to replace eq with ne (not equal). It should be something like this and it should return all values where ParentCategory is not empty.
Code: Select all
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby=Created desc&$expand=ParentCategory/Id&$filter=ParentCategory/Id ne null &$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby={LookupField}&$expand=ParentCategory/Id&$filter=startswith({LookupField}, '" + term + "') and ParentCategory/Id ne null &$top=10";
}
Cheers
Hi,
Nope, this code still not working. In your dropdown I get "Load failed", in Chrome console I see this stuff:
http://prntscr.com/groa6s
Tried to go to this url http://sp2013-dev/BNP/_api/web/lists('3 ... 6798545866:
Got
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/0 ... s/metadata">
<m:code>-2146232060, Microsoft.SharePoint.SPException</m:code>
<m:message xml:lang="en-US">Exception from HRESULT: 0x80131904</m:message>
</m:error>
What's wrong with my code?
Nope, this code still not working. In your dropdown I get "Load failed", in Chrome console I see this stuff:
http://prntscr.com/groa6s
Tried to go to this url http://sp2013-dev/BNP/_api/web/lists('3 ... 6798545866:
Got
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/0 ... s/metadata">
<m:code>-2146232060, Microsoft.SharePoint.SPException</m:code>
<m:message xml:lang="en-US">Exception from HRESULT: 0x80131904</m:message>
</m:error>
What's wrong with my code?
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello!
I am not exactly sure what is wrong with the code as it should return at least some results. Can you show me the Source List you are using for this Lookup?
Also, make sure that the field we are checking has internal name ParentCategory. You can check it by going to List Settings, clicking on the column and checking the URL. Internal name can be different from displayed name and we need to know the internal name to get the results here.
I am not exactly sure what is wrong with the code as it should return at least some results. Can you show me the Source List you are using for this Lookup?
Also, make sure that the field we are checking has internal name ParentCategory. You can check it by going to List Settings, clicking on the column and checking the URL. Internal name can be different from displayed name and we need to know the internal name to get the results here.
Cheers
Hi,
Here's the description of my "Categories" list:
Content Type ID | ContentTypeId | ContentTypeId
Title | Text | Title
Approver Comments | Note | _ModerationComments
File Type | Text | File_x0020_Type
ParentCategory | Lookup | ParentCategory
ID | Counter | ID
Content Type | Computed | ContentType
Modified | DateTime | Modified
Created | DateTime | Created
Created By | User | Author
Modified By | User | Editor
Has Copy Destinations | Boolean | _HasCopyDestinations
Copy Source | Text | _CopySource
owshiddenversion | Integer | owshiddenversion
Workflow Version | Integer | WorkflowVersion
UI Version | Integer | _UIVersion
Version | Text | _UIVersionString
Attachments | Attachments | Attachments
Approval Status | ModStat | _ModerationStatus
Edit | Computed | Edit
Title | Computed | LinkTitleNoMenu
Title | Computed | LinkTitle
Title | Computed | LinkTitle2
Select | Computed | SelectTitle
Instance ID | Integer | InstanceID
Order | Number | Order
GUID | Guid | GUID
Workflow Instance ID | Guid | WorkflowInstanceID
URL Path | Lookup | FileRef
Path | Lookup | FileDirRef
Modified | Lookup | Last_x0020_Modified
Created | Lookup | Created_x0020_Date
Item Type | Lookup | FSObjType
Sort Type | Lookup | SortBehavior
Effective Permissions Mask | Computed | PermMask
Name | File | FileLeafRef
Unique Id | Lookup | UniqueId
Client Id | Lookup | SyncClientId
ProgId | Lookup | ProgId
ScopeId | Lookup | ScopeId
HTML File Type | Computed | HTML_x0020_File_x0020_Type
Edit Menu Table Start | Computed | _EditMenuTableStart
Edit Menu Table Start | Computed | _EditMenuTableStart2
Edit Menu Table End | Computed | _EditMenuTableEnd
Name | Computed | LinkFilenameNoMenu
Name | Computed | LinkFilename
Name | Computed | LinkFilename2
Type | Computed | DocIcon
Server Relative URL | Computed | ServerUrl
Encoded Absolute URL | Computed | EncodedAbsUrl
File Name | Computed | BaseName
Property Bag | Lookup | MetaInfo
Level | Integer | _Level
Is Current Version | Boolean | _IsCurrentVersion
Item Child Count | Lookup | ItemChildCount
Folder Child Count | Lookup | FolderChildCount
App Created By | Lookup | AppAuthor
App Modified By | Lookup | AppEditor
Here's the description of my "Categories" list:
Content Type ID | ContentTypeId | ContentTypeId
Title | Text | Title
Approver Comments | Note | _ModerationComments
File Type | Text | File_x0020_Type
ParentCategory | Lookup | ParentCategory
ID | Counter | ID
Content Type | Computed | ContentType
Modified | DateTime | Modified
Created | DateTime | Created
Created By | User | Author
Modified By | User | Editor
Has Copy Destinations | Boolean | _HasCopyDestinations
Copy Source | Text | _CopySource
owshiddenversion | Integer | owshiddenversion
Workflow Version | Integer | WorkflowVersion
UI Version | Integer | _UIVersion
Version | Text | _UIVersionString
Attachments | Attachments | Attachments
Approval Status | ModStat | _ModerationStatus
Edit | Computed | Edit
Title | Computed | LinkTitleNoMenu
Title | Computed | LinkTitle
Title | Computed | LinkTitle2
Select | Computed | SelectTitle
Instance ID | Integer | InstanceID
Order | Number | Order
GUID | Guid | GUID
Workflow Instance ID | Guid | WorkflowInstanceID
URL Path | Lookup | FileRef
Path | Lookup | FileDirRef
Modified | Lookup | Last_x0020_Modified
Created | Lookup | Created_x0020_Date
Item Type | Lookup | FSObjType
Sort Type | Lookup | SortBehavior
Effective Permissions Mask | Computed | PermMask
Name | File | FileLeafRef
Unique Id | Lookup | UniqueId
Client Id | Lookup | SyncClientId
ProgId | Lookup | ProgId
ScopeId | Lookup | ScopeId
HTML File Type | Computed | HTML_x0020_File_x0020_Type
Edit Menu Table Start | Computed | _EditMenuTableStart
Edit Menu Table Start | Computed | _EditMenuTableStart2
Edit Menu Table End | Computed | _EditMenuTableEnd
Name | Computed | LinkFilenameNoMenu
Name | Computed | LinkFilename
Name | Computed | LinkFilename2
Type | Computed | DocIcon
Server Relative URL | Computed | ServerUrl
Encoded Absolute URL | Computed | EncodedAbsUrl
File Name | Computed | BaseName
Property Bag | Lookup | MetaInfo
Level | Integer | _Level
Is Current Version | Boolean | _IsCurrentVersion
Item Child Count | Lookup | ItemChildCount
Folder Child Count | Lookup | FolderChildCount
App Created By | Lookup | AppAuthor
App Modified By | Lookup | AppEditor
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Okay, I am not sure what exactly is wrong then. There were errors I've noticed in the code on the previous page, but the one on this page should work just fine. I will give an example here and leave you the working code I've used, it should finally work I hope.
First, here is my Source List with ParentCategory Lookup field. It has some test values, but some rows are left empty: First, I am filtering to display all values where ParentCategory is NOT Null. I am using this code, same as before:
Here are my settings for NOT Null:
Here are my results for NOT Null:
Next, I am filtering to display all values where ParentCategory IS Null. I am using this code, slightly changed from before:
Here are my settings for IS Null:
Here are my results for IS Null:
Hope these examples are good and you'll get it to work for you as well. Let me know!
First, here is my Source List with ParentCategory Lookup field. It has some test values, but some rows are left empty: First, I am filtering to display all values where ParentCategory is NOT Null. I am using this code, same as before:
Code: Select all
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby=Created desc&$expand=ParentCategory/Id&$filter=ParentCategory/Id ne null &$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby={LookupField}&$expand=ParentCategory/Id&$filter=startswith({LookupField}, '" + term + "') and ParentCategory/Id ne null &$top=10";
}
Code: Select all
function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby=Created desc&$expand=ParentCategory/Id&$filter=ParentCategory/Id eq null &$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},ParentCategory/Id&$orderby={LookupField}&$expand=ParentCategory/Id&$filter=startswith({LookupField}, '" + term + "') and ParentCategory/Id eq null &$top=10";
}
Cheers
Hi,
Tried this query:
http://sp2013-dev/BNP/_api/web/lists/ge ... 0eq%20null
against this list:
Got this result:
<?xml version="1.0" encoding="utf-8"?><feed xml:base="http://sp2013-dev/BNP/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/0 ... s/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>9aa9342 ... /id><title /><updated>2017-10-04T19:57:10Z</updated><author><name /></author></feed>
What's wrong with the query?
Tried this query:
http://sp2013-dev/BNP/_api/web/lists/ge ... 0eq%20null
against this list:
Got this result:
<?xml version="1.0" encoding="utf-8"?><feed xml:base="http://sp2013-dev/BNP/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/0 ... s/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>9aa9342 ... /id><title /><updated>2017-10-04T19:57:10Z</updated><author><name /></author></feed>
What's wrong with the query?
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello, senglory!
Can you simply send me a screenshot of your settings for the Cross-site Lookup, including Advanced settings code? That would be most helpful.
What do you mean by "this query"? Unfortunately, I can't use this URL to give any advice as I don't how exactly it's being used.Tried this query:
http://sp2013-dev/BNP/_api/web/lists/ge ... 0eq%20null
Can you simply send me a screenshot of your settings for the Cross-site Lookup, including Advanced settings code? That would be most helpful.
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 2 guests