+ <odc:PowerQueryMashupData><Mashup xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/DataMashup"><Client>EXCEL</Client><Version>2.85.741.0</Version><MinVersion>2.21.0.0</MinVersion><Culture>en-AU</Culture><SafeCombine>false</SafeCombine><Items><Query Name="ServiceURL"><Description>The ServiceAPI URL</Description><Formula><![CDATA[let Source = "http://localhost/ServiceAPI/" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true] in Source]]></Formula><IsParameterQuery xsi:nil="true" /><IsDirectQuery xsi:nil="true" /></Query><Query Name="PageSize"><Description>Number of objects (e.g. Records) to return in each page request.</Description><Formula><![CDATA[let Source = 397 meta [IsParameterQuery=true, Type="Number", IsParameterQueryRequired=true] in Source]]></Formula><IsParameterQuery xsi:nil="true" /><IsDirectQuery xsi:nil="true" /></Query><Query Name="CMSavedSearch"><Description /><Formula><![CDATA[let Source = (savedSearchId as text) as table => let friendlyRowValues = (row) => let tmoColumns = {"Uri"}, locationColumns = {"Uri"}, 	 refMainObjectFieldTransformations = List.Transform(tmoColumns, each {_, @friendlyRowValues}), refLocationFieldTransformations = List.Transform(locationColumns, each {_, @friendlyRowValues}), 	 v = if Value.Type(row) = type text then row else if Value.Type(row) = type number then row else if row is null then null else if Record.HasFields(row, "TrimType") and row[TrimType] = "Location" then Record.TransformFields(row, refLocationFieldTransformations) else if Record.HasFields(row, "TrimType") then Record.TransformFields(row, refMainObjectFieldTransformations) 	 else if Record.HasFields(row, "Value") then 	 	row[Value]? 	 else if Record.HasFields(row, "IsTimeClear") then 	 	row[DateTime]? 	 else 	 	row 	in 	 v, getPropertyList = (savedSearchDetails as record, savedSearchId as text) as record => let 			searchQuery = [q="unkSaved:" & savedSearchId, pageSize="1", excludeCount="true",propertySets="FromSearch", IncludePropertyDefs="true"], 			options = [ 				Headers=[#"Accept"="application/json", #"Cache-Control"="no-cache, no-store, must-revalidate"], 				Query=searchQuery], 			Source = Json.Document(Web.Contents(ServiceURL & savedSearchDetails[trimType] , options)) in Source[PropertiesAndFields], getSavedSearchDetails = ( savedSearchId as text) as record => let 			searchQuery = [properties="SavedSearchQueryString,SavedSearchObjectType"], 			options = [ 				Headers=[#"Accept"="application/json"], 				Query=searchQuery], 			Source = Json.Document(Web.Contents(ServiceURL & "savedsearch/" & savedSearchId , options)) in [trimType=Source[Results]{0}[SavedSearchObjectType][Value], query= Source[Results]{0}[SavedSearchQueryString][Value]], 	runSearch = (startAt as number, savedSearchDetails as record, properties as text) as record => 		let 			searchQuery = [rnd=Number.ToText(Number.Random()), q=savedSearchDetails[query], descendantProperties="NameString,ToolTip", pageSize=Number.ToText(PageSize), excludeCount="true",properties=properties, start=Number.ToText(startAt)], 			options = [ 				Headers=[#"Accept"="application/json", #"Content-Type"="application/json", #"Cache-Control"="no-cache, no-store, must-revalidate"], 				Query=searchQuery, RelativePath = savedSearchDetails[trimType]], 			Source = Json.Document(Web.Contents(ServiceURL, options)) 					in 			 Source , savedSearchDetails = getSavedSearchDetails(savedSearchId), searchResults = List.Skip(List.Generate(() => [IsMore = null, Start = 1, WebCall = {}, Results = null], each [Results] = null or List.Count([Results]) > 0, each [WebCall = runSearch(_[Start], savedSearchDetails, Text.Combine(propertyList, ",")), IsMore = WebCall[HasMoreItems], Start=_[Start]+PageSize, Results = WebCall[Results]], each [Results]),1), PropertiesAndFields = getPropertyList(savedSearchDetails, savedSearchId ), 			recordPropertyTable = Record.ToTable(PropertiesAndFields), 			Value = recordPropertyTable {0}[Value], 			propertyTable = Table.FromList(Value, Splitter.SplitByNothing(), null, null, ExtraValues.Error), 			propertyColumn = if Table.HasColumns(propertyTable,"Column1") then Table.ExpandRecordColumn(propertyTable , "Column1", {"Id"}, {"Column1.Id"}) else error Error.Record("error reason", "error message", "error detail"),			 			propertyList = propertyColumn[Column1.Id], 			#"Converted to Table" = Table.FromList(List.Combine(searchResults), Splitter.SplitByNothing(), null, null, ExtraValues.Error), 			 #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"RecordDateCreated", "RecordNumber", "RecordRecordType", "RecordTitle", "IsEnableTrasaction", "TrimType", "Uri", "Fields"}), 			 			fieldNames = List.Select(propertyList, each not (Text.StartsWith(_, savedSearchDetails[trimType]) or _ = "Uri")), 			#"Expanded Column1.Fields" = Table.ExpandRecordColumn(#"Expanded Column1", "Fields", fieldNames, fieldNames), 			#"Column Transformations" = List.Transform(propertyList, each {_, friendlyRowValues}), 			pageAsTable = Table.FromRecords(Table.TransformRows(#"Expanded Column1.Fields", (row) => Record.TransformFields(row, #"Column Transformations"))) in pageAsTable in Source]]></Formula><IsParameterQuery xsi:nil="true" /><IsDirectQuery xsi:nil="true" /></Query></Items></Mashup></odc:PowerQueryMashupData>
0 commit comments