“Lookup Name Lookup Value List” and Sitecore PowerShell – a perfect match in Sitecore heaven

Dear developers, I hope you are well out there. Today’s post will be a short one. 

I recently had to build a custom Submit Action (for a Sitecore Form). One of the requirements was to map Sitecore Forms fields with “CRM fields”, and the editors should do the “mapping”.

I will not cover how the Submit Action was built(let’s save it for another post), instead, we will go directly to the “mapping” part. 

Lookup Name Lookup Value List – what a lovely little “hidden” gem. This excellent control has been in Sitecore for ages, but I have never used it until now. It’s the perfect “mapping” control.

It allows you to point to 2 sources:

And for the editors, it will look like this 🙂

But in this case, we want to list “forms fields” from a “selected” Sitecore Form. So we’ve added a Droplink field that lists(points to) the Sitecore forms:

Now, to the tricky part!

In the “Lookup Name Lookup Value List”, we want to point to the “selected” Sitecore Form and list all its forms fields 

So time for some serious XPath queries(I thought), but no success 😢

So I did some Googling, and guess what… You can set a Sitecore PowerShell script to a source (I thought this was for datasources only). https://doc.sitecorepowershell.com/modules/integration-points/data-sources – How cool is that!

So I created a script that grabs the selected item and lists its children(forms fields)

function GetSelectedFormFieds {

	$currentItem = Get-Item .
	$selectedForm = Get-Item -Path "master:" -ID $currentItem.PSFields.SelectedSitecoreForm.Value
	Get-ChildItem -ID $selectedForm.Id -Recurse | Where-Object { $_.TemplateName -eq 'Input' -or $_.TemplateName -eq 'Dropdown List' -or $_.TemplateName -eq 'List' -or $_.TemplateName -eq 'Email' } 
}

GetSelectedFormFieds

And then in the Lookup Name Lookup Value List, we will set the “script” in the source together with the “query:../”.

This means that in the first dropdown we list all the “forms fields” from the “selected” Sitecore Form, and in the second dropdown, we list some children(from the current item).

Lookup Name Lookup Value List and Sitecore PowerShell, are the perfect match in Sitecore heaven 😍

Sitecore PowerShell is a true lifesaver. Thank you, Adam Najmanowicz and Michael West!

That’s all for now folks 😊


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.