# WSP.UCC-6.Views.ps1

function HideContentTypeFromList($listTitle, $hideContentTypes) 
{
	try
	{
		$lib = GetPnPList $listTitle -Includes
		$rootFolder = $lib.RootFolder
		foreach ($hideContentType in $hideContentTypes)
		{
			$contentTypeToHide = GetPnPContentType $hideContentType $lib
			$list = New-Object "System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]"
			foreach ($i in $rootFolder.UniqueContentTypeOrder) 
			{
				if ($i.StringValue -ne $contentTypeToHide.StringId) 
				{
					$list.Add($i)
				}
			}
			
			$rootFolder.UniqueContentTypeOrder = $list
			$rootFolder.Update()
		}

		$lib.Update()
		Invoke-PnPQuery
	}
	catch 
	{
		Error "Error hiding content types $hideContentTypes in list $listTitle : $($_.Exception.Message)"
	}
}

function ChangeFieldTitle($fieldName, $newTitle, $listTitle, [switch]$required)
{
	$field = GetPnPField $fieldName $listTitle
	$field.Title = $newTitle
	if ($required) 
	{
		$field.Required = $required
	}
	
	$field.Update()
	Invoke-PnPQuery
}

function AddCtAndViews 
{
    $web = Get-PnPWeb
    $relativeURL = $web.ServerRelativeUrl

    Info "Views / Forms..."
		
	try
	{
		# List Agents
		$listTitle = "Agents" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("Agent")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("wsp_ucc_Agent", "wsp_ucc_Order", "wsp_ucc_Formal", "CustomHours", "wsp_ucc_agent_aci", "wsp_ucc_agent_teamsupn", "wsp_ucc_agent_teamsphone") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Businesshours
		$listTitle = "Businesshours" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("Businesshours")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("wsp_ucc_day", "wsp_ucc_Start", "wsp_ucc_End", "wsp_ucc_AllDay") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List CallClassifications
		$listTitle = "CallClassifications" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("CallClassification")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("LinkTitle", "wsp_ucc_cc_level") -Default
		# Add forms
		AddForms $relativeURL $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List CallSummary
		$listTitle = "CallSummary" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("CallSummary")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("LinkTitle", "wsp_ucc_StartTime", "wsp_ucc_InQueueTime", "wsp_ucc_AcceptedTime", "wsp_ucc_EndTime", "wsp_ucc_Accepted", "wsp_ucc_QueueTime", "wsp_ucc_SkillChosen", "wsp_ucc_InitialAgent", "wsp_ucc_Customer", "QualityMonitor") -Default
		AddPnPView $listTitle "MissedCallsToDay" "MissedCallsToday" 30 "<Where><And><Eq><FieldRef Name=""wsp_ucc_Accepted"" /><Value Type=""Boolean"">0</Value></Eq><Eq><FieldRef Name=""wsp_ucc_StartTime"" /><Value Type=""DateTime""><Today /></Value></Eq></And></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("wsp_ucc_StartTime", "wsp_ucc_Customer", "wsp_ucc_SkillChosen")
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
	
	try
	{
		# List Endpoints
		$listTitle = "Endpoints" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("ModalityEndpoint", "SystemEndpoint", "MainEndpoint", "DefaultRoutingEndpoint")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<GroupBy Collapse=""FALSE""><FieldRef Name=""wsp_ucc_endpoints_type"" /></GroupBy><OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("LinkTitle", "wsp_ucc_modality", "wsp_ucc_skill", "wsp_ucc_endpoints_ParentQuestion", "wsp_ucc_Priority", "wsp_ucc_endpoints_enablerouting") -Default
		AddPnPView $listTitle "ModalityEndpointView" "ModalityEndpointView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">ModalityEndpoint</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_modality", "wsp_ucc_skill", "wsp_ucc_endpoints_ParentQuestion", "wsp_ucc_Priority", "wsp_ucc_endpoints_enablerouting")
		AddPnPView $listTitle "SystemEndpointView" "SystemEndpointView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">SystemEndpoint</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle")
		AddPnPView $listTitle "MainEndpointView" "MainEndpointView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">MainEndpoint</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_endpoints_enablerouting")
		AddPnPView $listTitle "DefaultRoutingEndpointView" "DefaultRoutingEndpointView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">DefaultRoutingEndpoint</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle")
		# Add forms
	   	AddForms $relativeURL $listTitle @("ModalityEndpointView", "SystemEndpointView", "MainEndpointView", "DefaultRoutingEndpointView")
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{	   
		# List Holidays
		$listTitle = "Holidays"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("HolidayItem")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("LinkTitle", "wsp_ucc_holidays_startdatetime", "wsp_ucc_holidays_enddatetime", "wsp_ucc_holidays_ivrquestion") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Holiday" $listTitle 
		# Change validation
		$holidays = GetPnPList $listTitle
		$holidays.ValidationFormula = "=[Start datetime]<=[End datetime]"
		$holidays.ValidationMessage = "Start datetime cannot be lower than End datetime"
		$holidays.Update()
		Invoke-PnPQuery
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List IDRQuestions
		$listTitle = "IDRQuestions"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("IDRQuestion", "IDRSystemItem")
		HideContentTypeFromList $listTitle @("IDRSystemItem")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy><GroupBy Collapse=""FALSE""><FieldRef Name=""wsp_ucc_idr_queue"" /></GroupBy>" @("LinkTitle", "wsp_ucc_idr_parent", "wsp_ucc_idr_question", "wsp_ucc_idr_choice", "wsp_ucc_idr_answer", "wsp_ucc_idr_skill") -Default
		AddPnPView $listTitle "IDRQuestionView" "IDRQuestionView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IDRQuestion</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True""/></OrderBy>" @("LinkTitle", "wsp_ucc_idr_parent", "wsp_ucc_idr_question", "wsp_ucc_idr_choice", "wsp_ucc_idr_answer", "wsp_ucc_idr_skill")
		# Add forms
		AddForms $relativeURL $listTitle @("IDRQuestionView")
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{	   
		# List IVRQuestions
		$listTitle = "IVRQuestions"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("IVRQuestionItem", "IVRHolidayQuestionItem", "IVRCallbackItem", "IVRSystemItem", "IVRCustomSystemItem")
		HideContentTypeFromList $listTitle @("IVRSystemItem", "IVRCustomSystemItem")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<GroupBy Collapse=""FALSE""><FieldRef Name=""wsp_ucc_ivr_queue"" /></GroupBy><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""Title"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ivr_action", "wsp_ucc_ivr_Parent", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_choice", "wsp_ucc_ivr_choicetimeout", "wsp_ucc_Answer", "wsp_ucc_ivr_AudioAnswer", "wsp_ucc_ivr_description" ) -Default
		AddPnPView $listTitle "QuestionItemView" "QuestionItemView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IVRQuestionItem</Value></Eq></Where><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""Title"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ivr_action", "wsp_ucc_ivr_Parent", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_choice", "wsp_ucc_ivr_choicetimeout", "wsp_ucc_Answer", "wsp_ucc_ivr_AudioAnswer", "wsp_ucc_ivr_description", "wsp_ucc_ivr_phrase" )
		AddPnPView $listTitle "CallbackItemView" "CallbackItemView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IVRCallbackItem</Value></Eq></Where><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_description" )
		AddPnPView $listTitle "SystemItemView" "SystemItemView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IVRSystemItem</Value></Eq></Where><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_description" )
		AddPnPView $listTitle "CustomSystemItemView" "CustomSystemItemView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IVRCustomSystemItem</Value></Eq></Where><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ivr_action", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_choice", "wsp_ucc_ivr_choicetimeout", "wsp_ucc_ivr_enableskilldependenc", "wsp_ucc_ivr_skilldependencies", "wsp_ucc_ivr_description" )
		AddPnPView $listTitle "HolidayQuestionItemView" "HolidayQuestionItemView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">IVRHolidayQuestionItem</Value></Eq></Where><OrderBy><FieldRef Name=""wsp_ucc_ivr_order"" /><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ivr_action", "wsp_ucc_ivr_Parent", "wsp_ucc_Question", "wsp_ucc_ivr_AudioQuestion", "wsp_ucc_ivr_choice", "wsp_ucc_ivr_choicetimeout", "wsp_ucc_Answer", "wsp_ucc_ivr_AudioAnswer", "wsp_ucc_ivr_description" )
		# Add forms
		AddForms $relativeURL $listTitle @("QuestionItemView", "CallbackItemView", "SystemItemView", "CustomSystemItemView", "HolidayQuestionItemView")
		# Change title in ct
		try
		{
			SetContentTypeFieldDisplayName "IVRQuestions" "IVRHolidayQuestionItem" "Title" "HolidayQuestion"
		}
		catch 
		{ 
			if ($SPversion -eq "online") 
			{
				Error "Cannot set DisplayName on 'Title' column in 'IVRHolidayQuestionItem' content type in '$listTitle' list :: $($_.Exception.Message)"
			}
		}
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{	
		# List OutboundDialerCalls
		$listTitle = "OutboundDialerCalls"
		# Add CTs	
		AddPnPContentTypesToList $listTitle @("OutboundDialerCall", "AutonomousDialerItem")
		# Add fields
		AddPnPFieldFromXml '<Field ID="{50174ce4-8b21-4f8d-aa9a-5d44b7d25e23}" Type="Text" Name="wsp_ucc_odc_agentsip" DisplayName="Agent Sip" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		AddPnPFieldFromXml '<Field ID="{e3267af0-da0d-4701-96fc-4047f3eb396e}" Type="Text" Name="wsp_ucc_odc_result" DisplayName="Result" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">OutboundDialerCall</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_odc_processed", "wsp_ucc_odc_skill", "wsp_ucc_odc_order", "wsp_ucc_odc_prio", "wsp_ucc_odc_day", "wsp_ucc_odc_datestart", "wsp_ucc_odc_timestart", "wsp_ucc_odc_dateend", "wsp_ucc_odc_timeend", "wsp_ucc_odc_agentsip", "wsp_ucc_odc_result", "wsp_ucc_odc_retries") -Default
		AddPnPView $listTitle "AutonomousDialerView" "AutonomousDialerView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">AutonomousDialerItem</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_odc_processed", "wsp_ucc_odc_order", "wsp_ucc_odc_prio", "wsp_ucc_odc_prewelcomemessage", "wsp_ucc_odc_prewelcomeaudiomessage", "wsp_ucc_odc_day", "wsp_ucc_odc_datestart", "wsp_ucc_odc_timestart", "wsp_ucc_odc_dateend", "wsp_ucc_odc_timeend", "wsp_ucc_odc_result", "wsp_ucc_odc_retries")
		# Add forms
		AddForms $relativeURL $listTitle @("AutonomousDialerView")
		# Change Title
		ChangeFieldTitle "Title" "Invite" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Playlists
		$listTitle = "Playlists"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("PlaylistItem")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<GroupBy Collapse=""FALSE""><FieldRef Name=""Title"" /></GroupBy><OrderBy><FieldRef Name=""wsp_ucc_pl_order"" /><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_pl_audiofile", "wsp_ucc_pl_order", "wsp_ucc_pl_active") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Playlist" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List PluginAttributes
		$listTitle = "PluginAttributes" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("PluginAttribute")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<GroupBy Collapse=""$false"" GroupLimit=""100""><FieldRef Name=""wsp_ucc_pa_category"" Ascending=""True""/></GroupBy><OrderBy><FieldRef Name=""wsp_ucc_pa_order"" Ascending=""$true"" /></OrderBy>" @("Title", "wsp_ucc_pa_systemname", "wsp_ucc_pa_show", "wsp_ucc_pa_show_toast", "wsp_ucc_pa_order", "wsp_ucc_pa_fieldtype", "wsp_ucc_pa_hyperlink", "wsp_ucc_pa_open", "wsp_ucc_pa_category") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Display Name" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List PluginFlowSettings
		$listTitle = "PluginFlowSettings" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("PluginFlowSetting")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""wsp_ucc_pfs_order"" Ascending=""$true"" /></OrderBy>" @("LinkTitle", "wsp_ucc_pfs_operator", "wsp_ucc_pfs_order", "wsp_ucc_pfs_condition", "wsp_ucc_pfs_flag", "wsp_ucc_pfs_flagvalue", "wsp_ucc_pfs_action", "wsp_ucc_pfs_skill", "wsp_ucc_pfs_prompt", "wsp_ucc_pfs_parentquestion", "wsp_ucc_pfs_pluginattribute", "wsp_ucc_pfs_message") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Attribute" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
   		
	try
	{    
		# List PluginSettings
		$listTitle = "PluginSettings" 
		# Add CTs
		AddPnPContentTypesToList $listTitle @("PluginSetting")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<GroupBy Collapse=""$false"" GroupLimit=""100""><FieldRef Name=""wsp_ucc_ps_scope"" Ascending=""True""/></GroupBy><OrderBy><FieldRef Name=""Title"" Ascending=""$true"" /></OrderBy>" @("Title", "wsp_ucc_ps_value", "wsp_ucc_ps_scope", "wsp_ucc_ps_prompt") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Setting" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List PromptsConfig
		$listTitle = "PromptsConfig"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("PromptConfig")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /><FieldRef Name=""ID"" /></OrderBy>" @("PromptId", "Welcome", "wsp_ucc_pc_audiofile", "Happy", "Sad", "SuccesAction") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List QualityMonitorConfig
		$listTitle = "QualityMonitorConfig"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("QualityMonitorConfig")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("Welcome", "ValueStart", "ValueEnd", "GoodBye", "WelcomeAudio", "GoodByeAudio", "wsp_ucc_qmc_modality", "wsp_ucc_qmc_order") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List ReasonCodes
		$listTitle = "ReasonCodes"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("ReasonCode")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_rc_code", "wsp_ucc_rc_presencestate") -Default
		# Add forms
		AddForms $relativeURL $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Routing
		$listTitle = "Routing"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("UCCRouting", "InboundRouting")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "ContentType", "wsp_ucc_routing_match_from", "wsp_ucc_routing_match_to", "wsp_ucc_routing_action", "wsp_ucc_routing_active") -Default
		AddPnPView $listTitle "UCCRoutingView" "UCCRoutingView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">UCCRouting</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_routing_exactmatch", "wsp_ucc_routing_match_from", "wsp_ucc_routing_action", "wsp_ucc_routing_matchendpoint", "wsp_ucc_routing_order", "wsp_ucc_routing_active")
		AddPnPView $listTitle "InboundRoutingView" "InboundRoutingView" 100 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">InboundRouting</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_routing_match_from", "wsp_ucc_routing_match_to", "wsp_ucc_routing_action", "wsp_ucc_routing_order", "wsp_ucc_routing_active")
		# Add forms
		AddForms $relativeURL $listTitle @("UCCRoutingView", "InboundRoutingView")
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Settings
		$listTitle = "Settings"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("Setting")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<GroupBy Collapse=""FALSE""><FieldRef Name=""wsp_ucc_scope"" /></GroupBy><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("wsp_ucc_Key", "Edit", "wsp_ucc_Value", "wsp_ucc_Description") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List settingsList
		$listTitle = "settingsList"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("SettingsList")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<GroupBy Collapse=""FALSE""><FieldRef Name=""wsp_ucc_scope"" /></GroupBy><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_URL", "wsp_ucc_HeaderTitle", "wsp_ucc_sort", "wsp_ucc_visible") -Default
		# Add forms
		AddForms $relativeURL $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List SettingValues
		$listTitle = "SettingValues"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("SettingValue")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 100 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_sv_type", "wsp_ucc_sv_value", "wsp_ucc_sv_default", "wsp_ucc_sv_description", "wsp_ucc_sv_scope", "wsp_ucc_sv_settinggroup", "wsp_ucc_sv_readonly", "wsp_ucc_sv_active") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Key" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Skills
		$listTitle = "Skills"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("Skill", "ChatSkill", "AvailabilitySkill", "CountDownSkill", "CountdownAvailabilitySkill", "ForwardSkill", "ChatForwardSkill")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "ContentType") -Default
		AddPnPView $listTitle "NormalSkillView" "NormalSkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">Skill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ShowOnWallboard")
		AddPnPView $listTitle "CountDownSkillView" "CountDownSkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">CountDownSkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ShowOnWallboard", "StartCountDownSeconds", "EndCountDownSeconds", "wsp_ucc_skills_escapeskill")
		AddPnPView $listTitle "AvailabilitySkillView" "AvailabilitySkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">AvailabilitySkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ShowOnWallboard", "Availability", "wsp_ucc_skills_escapeskill")
		AddPnPView $listTitle "CountdownAvailabilitySkillView" "CountdownAvailabilitySkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">CountdownAvailabilitySkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ShowOnWallboard", "Availability", "StartCountDownSeconds", "EndCountDownSeconds", "wsp_ucc_skills_escapeskill")
		AddPnPView $listTitle "ForwardSkillView" "ForwardSkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">ForwardSkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ForwardToSip", "ForwardWithDTMF")
		AddPnPView $listTitle "ChatSkillView" "ChatSkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">ChatSkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ShowOnWallboard")
		AddPnPView $listTitle "ChatForwardSkillView" "ChatForwardSkillView" 30 "<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">ChatForwardSkill</Value></Eq></Where><OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_ForwardToSip", "wsp_ucc_ShowOnWallboard")
		# Add forms
		AddForms $relativeURL $listTitle @("NormalSkillView", "CountDownSkillView", "AvailabilitySkillView", "CountdownAvailabilitySkillView", "ForwardSkillView", "ChatSkillView", "ChatForwardSkillView")
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List SkillsPerAgent
		$listTitle = "SkillsPerAgent"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("SkillsPerAgent")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 500 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("wsp_ucc_spa_skill", "wsp_ucc_Score", "wsp_ucc_spa_Agent") -Default
		AddPnPView $listTitle "GroupBySip" "GroupBySip" 500 "<GroupBy><FieldRef Name=""wsp_ucc_spa_Agent"" /></GroupBy><OrderBy><FieldRef Name=""wsp_ucc_Score"" /></OrderBy>" @("wsp_ucc_spa_skill", "wsp_ucc_Score", "wsp_ucc_spa_Agent")
		AddPnPView $listTitle "GroupBySkill" "GroupBySkill" 500 "<GroupBy><FieldRef Name=""wsp_ucc_spa_skill"" /></GroupBy><OrderBy><FieldRef Name=""wsp_ucc_spa_skill"" /></OrderBy>" @("wsp_ucc_spa_skill", "wsp_ucc_Score", "wsp_ucc_spa_Agent")
		# Add forms
		AddForms $relativeURL $listTitle @("GroupBySip", "GroupBySkill")
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Supervisors
		$listTitle = "Supervisors"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("Supervisor")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("wsp_ucc_Supervisor") -Default
		# Add forms
		AddForms $relativeURL $listTitle
		# Hide Title
		HideField "Title" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
		
	try
	{
		# List Version
		$listTitle = "Version"
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle") -Default
       	# Add forms
		AddForms $relativeURL $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}

	try
	{
		# List VoicemailAgents
		$listTitle = "VoicemailAgents"
		# Add CTs
		AddPnPContentTypesToList $listTitle @("VoicemailAgent")
		# Add views
		AddPnPView $listTitle "AllItems" "AllItems" 30 "<OrderBy><FieldRef Name=""ID"" /></OrderBy>" @("LinkTitle", "wsp_ucc_voicemailagents_uri", "wsp_ucc_voicemailagents_priority") -Default
       	# Add forms
		AddForms $relativeURL $listTitle
		# Change Title
		ChangeFieldTitle "Title" "Name" $listTitle
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}

	try
	{
		# List Voicemails
		$listTitle = "Voicemails"
		# Add fields
		AddPnPFieldFromXml '<Field Type="Text" Name="Caller" DisplayName="Caller" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		AddPnPFieldFromXml '<Field Type="Boolean" Name="Delivered" DisplayName="Delivered" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		AddPnPFieldFromXml '<Field Type="DateTime" Name="DeliveredDate" DisplayName="DeliveredDate" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		AddPnPFieldFromXml '<Field Type="Text" Name="Flow" DisplayName="Flow" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		AddPnPFieldFromXml '<Field Type="DateTime" Name="RecordedDate" DisplayName="RecordedDate" Required="FALSE" Group="AnywhereNow" />' $null $null $listTitle -IgnoreDuplicateException
		# Add views
		AddPnPView $listTitle "AllItems" "All Documents" 30 '<OrderBy><FieldRef Name="FileLeafRef" /></OrderBy>' @("DocIcon", "LinkFilename", "Modified", "Editor", "Caller", "Delivered", "DeliveredDate", "Flow", "RecordedDate") -Default -RemoveIfExists
	}
	catch 
	{
		Error "Exception on list $listTitle : $($_.Exception.Message)"
	}
}
