

That said – from my tests I?ve not seen any noticeable slow down or any measurable impact where my script would be slower than something that you would solve using the code: datasource of the same complexity.
#POWERSHELL ISE VISUAL STUDIO DARK THEME CODE#
Word of caution is to make sure your script runs in reasonable time just as you would with your code solution, as while it does not impact the delivery side of Sitecore a poorly performing script might make your editors not send you a Christmas card. Return session.ExecuteScriptPart(script, false).Cast().ToArray() session should return objects rather than text to be displayed "false" value provided as the second parameter specifies that put the script in context of the current item String script = (scriptItem.Fields != null) ScriptSession session = new ScriptSession(ApplicationNames.Default) ScriptSource = scriptSource.Replace("script:", "").Trim() get my script item from the Script library Protected static Item RunEnumeration(string scriptSource, Item item) Var itemArray = RunEnumeration(scriptLocation, contextItem) for every scripted source, run it through powershell Var scriptLocation = location.Replace("script:", "").Trim() Protected static string GetScriptedQueries(string sources, Itemįoreach (string location in new ListString(sources)) StringComparison.OrdinalIgnoreCase) > -1 Protected bool IsScripted(string dataSource) if no other queries to be served, no need to continue pipeline Var source = GetScriptedQueries(args.Source, args.Item, items) The solution hooks into the getLookupSourceItems pipeline like follows: Īnd the class that takes the pipeline input and executes PowerShell accordingly can look like the following: public void Process(GetLookupSourceItemsArgs args) Now in your template definition paste the path in the and prepend it with a ? script:? statement like follows: sitecore/system/Modules/PowerShell/Script Library/Īnd copy the script item path. Save your script in the Script library by using the Save button in ISE:įind your script in the script library which is located in your Master database under: Don?t format your results with format-list, format-table etc. The script should be returning items like the script above. Basically there?s plenty of flexibility there already. Interestingly the following fields do not use the pipeline:īut that?s understandable after you read John?s article on how the Data source is defined in those fields. Generally everything that uses the getLookupSourceItems pipeline should work with the scripting solution. even with 3rd party fields like ?Google Maps Multilist?.But maybe you?re not in a position to deploy that on your environment?įield data source is something you might want to have the most flexibility with. Something that would be beyond the reach of a regular Sitecore query and potentially something that you would really need to deliver code source for. anything you might want to build the code data source for?.based on where in the tree an item exist (some of it can be done with use of a ?query:?).based on engagement analytics parameters of the page.In a multisite/multimarket scenario you may want to show different items for each site.user name or role (in simplest case this can be done using right management, but maybe not always possible in a more elaborate scenario).your field may need to provide different set of items to choose from based on: Delivering complex functionality based on multiple criteria.Just to prove that both Sitecore and PowerShell are infinitely malleable and mixable, is good enough for me, but that?s not really the reason someone other than me would be interested in it.

So what a PowerShell and Sitecore nut does when he sees stuff like that? Obviously delivers a scripted data source! Why do that? I?ve also recently read a nice article by Ronald Nieuwenhuis on NewGuid about their approach to the subject. We delivered something similar in our internal libraries and it proved super useful ever since. Reading some time ago the Item Buckets documentation I discovered something really cool called code data sources.
