List.Contains
Indicates whether the list contains the value.
Syntax
List.Contains(
list as list,
value as any,
optional equationCriteria as any
) as logical
Remarks
Indicates whether the list list contains the value value. Returns true if value is found in the list, false otherwise. An optional equation criteria value, equationCriteria, can be specified to control equality testing.
Examples
Example #1
Find if the list {1, 2, 3, 4, 5} contains 3.
List.Contains({1, 2, 3, 4, 5}, 3)
Result:
true
Example #2
Find if the list {1, 2, 3, 4, 5} contains 6.
List.Contains({1, 2, 3, 4, 5}, 6)
Result:
false
Category
List.Membership functions
More examples
Implement this function to retrieve or calculate the service URL based on the data source path parameters
GetAuthorizationUrlFromWwwAuthenticate = (url as text) as text =>
let
// Sending an unauthenticated request to the service returns
// a 302 status with WWW-Authenticate header in the response. The value will
// contain the correct authorization_uri.
//
// Example:
// Bearer authorization_uri="https://login.microsoftonline.com/{tenant_guid}/oauth2/authorize"
responseCodes = {302, 401},
endpointResponse = Web.Contents(url, [
ManualCredentials = true,
ManualStatusHandling = responseCodes
])
in
if (List.Contains(responseCodes, Value.Metadata(endpointResponse)[Response.Status]?)) then
let
headers = Record.FieldOrDefault(Value.Metadata(endpointResponse), "Headers", []),
wwwAuthenticate = Record.FieldOrDefault(headers, "WWW-Authenticate", ""),
split = Text.Split(Text.Trim(wwwAuthenticate), " "),
authorizationUri = List.First(List.Select(split, each Text.Contains(_, "authorization_uri=")), null)
in
if (authorizationUri <> null) then
// Trim and replace the double quotes inserted before the url
Text.Replace(Text.Trim(Text.Trim(Text.AfterDelimiter(authorizationUri, "=")), ","), """", "")
else
error Error.Record("DataSource.Error", "Unexpected WWW-Authenticate header format or value during authentication.", [
#"WWW-Authenticate" = wwwAuthenticate
])
else
error Error.Unexpected("Unexpected response from server during authentication.");