Solution: Set a PWO DialogParameter Value via Script (Sharing is caring)

As discussed in the hidden Gems session at the recent UNITE conference there is a simple script to retrieve the value of a DialogParameter of a Request (PersonWantsOrg).

I faced now a situation to update a value (based on an External Decision) and want to share that script with you.

Basically it works like the QER_Get_ParameterValue_Of_ParameterSet_Of_PWO Script just expecting a value (if empty, value will be set empty).

Public Function CCC_Set_ParameterValue_Of_ParameterSet_Of_PWO( _
	ByVal keyPWO As String, _
	ByVal paramName As String, _
	Optional ByVal paramValue As String = ""
) As Boolean

	' Parameters:
	'	keyPWO: 	PersonWantsOrg.XObjectKey
	'	paramName:	ParameterName 
	'   paramValue: If empty, paramvalue is set empty
	
	'returns nothing, if the ParameterName was not found the DialogParameterSet
	'for use in processes to set parameter values (where a parameter with value nothing is not generated)
	
	If Not String.IsNullOrEmpty(keyPWO) AndAlso Not String.IsNullOrEmpty(paramName) Then
		
		'determine the DialogParameterSet of the request
		Dim pSet As String = Nothing
		Dim f As ISqlFormatter = Connection.SqlFormatter

		If Session.Source().TryGetSingleValue(Of String) _
				(Query.From("DialogParameterSet") _
					.Where(f.UidComparison("ObjectKeyUsedBy", keyPWO)) _
					.Select("UID_DialogParameterSet"), pSet) Then
			
				'get the DialogParameter as IEntity from the DialogParameterSet
				Dim param As IEntity = Nothing

				
				If Session.Source().TryGet _
				(Query.From("DialogParameter") _
					.Where(f.AndRelation( _
						f.UidComparison("UID_DialogParameterSet", pSet), _
						f.Comparison("ParameterName", paramName, ValType.String, CompareOperator.Equal, FormatterOptions.IgnoreCase))).SelectAll() _
						, EntityLoadType.Default _
						, param) Then
					
						param.PutValue("ParameterValue",paramValue)
						param.Save(session)
				End If
				
		Else
			'DialogParameterSet was not found
			Throw New ViException(#LD("No parameter set found for request {0}.", keyPWO)#, ExceptionRelevance.EndUser)
		End If
	
	End If
	
	Return Nothing
					
End Function