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)

  • The "On property change" script is used to dynamically determine whether a parameter is read-only or mandatory, for example.

    Example:

    The P2 parameter should be a mandatory field when the P1 parameter has the value Mandatory field. The following script must be stored with the P1 parameter:

    ParameterSet("P2").IsMandatory = (Value IsNot Nothing AndAlso Value.ToString() = "Pflichtfeld")

    But to simplify your use case a little bit, I propose to use to lookup against the Department table, select the UID_Department and in the where-clause use:

    EXISTS (
    		SELECT 1
    		FROM PersonInDepartment
    		WHERE PersonInDepartment.UID_Person = '%UserUID%'
    			AND PersonInDepartment.UID_Department = Department.UID_Department
    		)

  • 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.

  • For your use case involving Employee-Department associations and the selection of departments during product ordering in ITShop, you're on the right track with your current approach. To address your concerns:

    1. Using PersonInDepartment.XObjectKey as a DataSource in the parameter set is a reasonable choice to avoid errors. It's often preferable to use fields that are less likely to cause issues.

    2. You can indeed use the "On property changed script" in the Request Property to achieve your goal more logically. This approach can help streamline your workflow. Here's a simplified example of what the script might look like:

      // Assuming you have access to relevant variables and objects
      var selectedDepartment = RequestProperty.XObjectKey; // Retrieve the selected department from the Request Property

      // Now, you can update the PersonWantsOrg.UID_Department field
      PersonWantsOrg.UID_Department = selectedDepartment;

      // Don't forget to save the changes if needed
      PersonWantsOrg.Save();


      Remember to adapt the script according to your specific data structure and business logic. You may need to handle error-checking and validation based on your requirements.

      Since you are using One Identity Manager 9.1 and the HTML5-based Web portal (ApiServer), make sure to refer to the official documentation for any syntax and functionality specifics that might apply to your version.

      If you have any more questions or need further assistance, please feel free to ask.

      Best regards,

      Twin Mark 

      Fort Lauderdale Property Management

  • For your use case involving Employee-Department associations and the selection of departments during product ordering in ITShop, you're on the right track with your current approach. To address your concerns:

    1. Using PersonInDepartment.XObjectKey as a DataSource in the parameter set is a reasonable choice to avoid errors. It's often preferable to use fields that are less likely to cause issues.

    2. You can indeed use the "On property changed script" in the Request Property to achieve your goal more logically. This approach can help streamline your workflow. Here's a simplified example of what the script might look like:

      // Assuming you have access to relevant variables and objects
      var selectedDepartment = RequestProperty.XObjectKey; // Retrieve the selected department from the Request Property

      // Now, you can update the PersonWantsOrg.UID_Department field
      PersonWantsOrg.UID_Department = selectedDepartment;

      // Don't forget to save the changes if needed
      PersonWantsOrg.Save();

      Remember to adapt the script according to your specific data structure and business logic. You may need to handle error-checking and validation based on your requirements.

      Since you are using One Identity Manager 9.1 and the HTML5-based Web portal (ApiServer), make sure to refer to the official documentation for any syntax and functionality specifics that might apply to your version.

      If you have any more questions or need further assistance, please feel free to ask.

      Best regards,

      Twin Mark
      Fort Lauderdale Property Management