Request Property and data from PersonInDepartment

Hi all,

I am trying to solve the following use case:
An Employee is associated with several Departments through PersonInDepartment. When the Employee is ordering a product from ITShop, they should be able to select one of their Departments in a drop down list. This department should then be saved to PersonWantsOrg for further use (i.e. approval by the correct manager).

Currently I have created a request property with data source PersonInDepartment.XObjectKey and condition UID_Person = '%UserUID%'. I then added code in the OnSaving Script for PersonInDepartment that parses DialogParameterSet, DialogParameter and PersonInDepartment, and populates PersonWantsOrg.UID_Department. This works, but feels like a very cumbersome approach, and i beleive two of the steps could be solved better:

1. I have PersonInDepartment.XObjectKey as DataSource in the parameter set because I get an error message if I try to use PersonInDepartment.UID_Department. In the web-frontend I get "An error occured while processing your request". 
2. I feel that using the "On property changed script" in the Request Property is a more logical approach than using OnSaving script in PersonWantsOrg, but I'm not sure about the syntax here. Is it possible to use this script to populate PersonWantsOrg? Are there any example code that can help me out?

I am using One Identity Manager 9.1 and the new HTML5 based Web portal (ApiServer)

Parents
  • Hi Markus,

    Thanks for the reply. I have been working on other parts of the project and haven't been able to check back on this before now. 

    I decided to use PersonInDepartment.XObjectKey as data source since this presents the user with a simple dropdown instead of the popup for Department-selection. I then use the following On Saving-Script in the PersonWantsOrg table to populate PersonWantsOrg.UID_Department. Does ths seem like a ok solution? I feel like I'm traversing a lot of tables and using TryGetSingleValue several times, but I'm not sure if this can cause problems further down the road...

    Dim f As ISqlFormatter = Session.SqlFormatter
    
    ' Find DialogParameterSet where DialogParameterSet.ObjectKeyUsedBy = PersonWantsOrg.XObjectKey
    Dim whereClause = f.Comparison("ObjectKeyUsedBy", $XObjectKey$, ValType.String, CompareOperator.Equal)
    Dim exists As Boolean = Nothing
    
    Dim uidDialogParameterSet As String = Nothing
    exists = Session.Source().TryGetSingleValue(Of String)(Query.From("DialogParameterSet").Where(whereClause).Select("UID_DialogParameterSet"), uidDialogParameterSet)
    If exists Then
    	
    	' Find DialogParameter Where DialogParameter.UID_DialogParameterSet = DialogParameterSetUID_DialogParameterSet And ParameterName = "Employment"
    	Dim parameterValue As String = Nothing
    	Dim uidDialogParameter As String = Nothing
    	whereClause = f.AndRelation(f.UidComparison("UID_DialogParameterSet", uidDialogParameterSet),
    	                            f.Comparison("ParameterName", "Employment", ValType.String, CompareOperator.Equal))
    	exists = Session.Source().TryGetSingleValue(Of String)(Query.From("DialogParameter").Where(whereClause).Select("ParameterValue"), parameterValue)
    	Session.Source().TryGetSingleValue(Of String)(Query.From("DialogParameter").Where(whereClause).Select("UID_DialogParameter"), uidDialogParameter)
    	
    	If exists Then
    		' Find Department with XObjectKey = ParameterValue
    		Dim uidDepartment As String = Nothing
    		whereClause = f.Comparison("XObjectKey", parameterValue, ValType.String, CompareOperator.Equal)
    		exists = Session.Source().TryGetSingleValue(Of String)(Query.From("PersonInDepartment").Where(whereClause).Select("UID_Department"), uidDepartment)
    		
    		If exists Then
    		    ' Save UID_Department to the current PersonWantsOrg Object
    			Base.PutValue("UID_Department", uidDepartment)
    			
    			'Delete DialogParameter and DialogParameterSet to cleanup and prevent them from showing in the portal
    			If $OrderState$ = "Assigned" Then
    				Dim dbDialogParameter = Session.Source.Get("DialogParameter", uidDialogParameter)
    				Dim dbDialogParameterSet = Session.Source.Get("DialogParameterSet", uidDialogParameterSet)
    			    Using uow = Session.StartUnitOfWork()
    			
    			        ' Mark for deletion
    		            dbDialogParameter.MarkForDeletion()
    		            uow.Put(dbDialogParameter)
    			        uow.Commit()
    					
    		            dbDialogParameterSet.MarkForDeletion()
    		            uow.Put(dbDialogParameterSet)
    			        uow.Commit()
    			    End Using
    			End If
    		End If
    	End If
    End If

  • If you are not using any other parameter, I suggest using the legacy request properties. With these, you can set the value PersonWantsOrg.UID_Department directly.

Reply Children
No Data