Page 1 of 1

Filter Cross Site Lookup by Person Field

Posted: 13 Sep 2018
by RMIC
Hello,

my environment:
SharePoint Online
Cross-site lookup Version 1.4.4


How can I filter a cross-site lookup (resource) based on a person?
My starting situation:
I have a ticket list. Each ticket has a ticket creator (person field).
There are a list of resources. Each resource is assigned to an owner (person field).

When creating a ticket, a resource (cross-site-lookup) is assigned.
How can I filter the resource depending on the ticket creator?
Only the resources assigned to the ticket creator in the resources list should be displayed.

Thanks for your help!

Re: Filter Cross Site Lookup by Person Field

Posted: 13 Sep 2018
by AlexZver
Hi,

Please, use the following code:

Code: Select all

function (term, page) {
  var creator = fd.field('PersonCreator').value()[0];
  if (creator) {
  	var creatorEmail = creator.EntityData.Email;
  } else {
  	var creatorEmail = "";
  }
  
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Person/EMail&$orderby=Created desc&$expand=Person/EMail&$filter=Person/EMail eq '" + creatorEmail + "'&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Person/EMail&$orderby={LookupField}&$expand=Person/EMail&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and Person/EMail eq '" + creatorEmail + "'&$top=10";
}

'PersonCreator' is an internal name of the current form field, 'Person' is an internal name of lookup item field.

Re: Filter Cross Site Lookup by Person Field

Posted: 14 Sep 2018
by RMIC
Perfect. Thank you!