none
Code question... RRS feed

  • Question

  •  Im having an issue when trying to do a check to see if an attribute is present or if the attribute has a value of not true, but when using the code snip below, the sync server returns a bunch of "extension-attribute-not-present" errors stating: Microsoft.MetadirectoryServices.AttributeNotPresentException: Attribute "Attribute1" is not present.  When i remove the "Or Not mventry("Attribute").Value = "True" Then" piece, it will run without errors, but skips accounts that should be run through the rest of the script to evaluate if the person should be termed or not.  basically, i would like to check to see if the attribute is present or not true.  Any ideas?

      If Not mventry("Attribute1").IsPresent Or Not mventry("Attribute").Value = "True" Then

    Wednesday, August 7, 2013 1:56 PM

All replies

  • Basically, you can't check if an attribute is present and check the value of that attribute on the same line.

    I'm not sure if you meant to be checking two different attributes in that line. First check to see if the attribute is present then check to see if it is set to true. Use the "Else" if you need to code for additional scenarios. 

    Mark


    Mark Creekmore - BlueVault Software http://www.bluevaultsoftware.com

    Wednesday, August 7, 2013 2:14 PM
  • Yes, its the same attribute that i m checking on.  here is the full snippit of code.  the problem is it skips over everything even if the value is false for quickterm

    If Not mventry("QuickTerm").IsPresent Then

                        'EMPL_STATUS ='T'
                        If csentry("EMPL_STATUS").IsPresent Then
                            Dim hrEmplStatus As String = csentry("EMPL_STATUS").Value.ToUpper  'Check for Status not null

                            If hrEmplStatus.Equals("T") Then
                                If csentry("ACCESS_TERMDATE").IsPresent Then
                                    Dim hrAccessTermDate As Date = Date.Parse(csentry("ACCESS_TERMDATE").Value)
                                    If hrAccessTermDate <= Date.Today.AddDays(2) Then
                                        mventry("Terminated").Value = "true"
                                    Else
                                        mventry("Terminated").Value = "false"
                                    End If

                                ElseIf csentry("TERMINATION_DT").IsPresent Then
                                    Dim hrTerminationDate As Date = Date.Parse(csentry("TERMINATION_DT").Value)

                                    If hrTerminationDate <= Date.Today.AddDays(2) Then
                                        mventry("Terminated").Value = "true"
                                    Else
                                        mventry("Terminated").Value = "false"
                                    End If
                                Else
                                    mventry("Terminated").Value = "false"
                                End If

                                'Status = 'L'
                            ElseIf hrEmplStatus.Equals("L") Then

                                If csentry("ACCESS_TERMDATE").IsPresent Then
                                    Dim hrADate As Date = Date.Parse(csentry("ACCESS_TERMDATE").Value)
                                    If hrADate <= Date.Today.AddDays(2) Then
                                        mventry("Terminated").Value = "true"
                                    Else
                                        mventry("Terminated").Value = "false"
                                    End If

                                ElseIf csentry("EFFDT").IsPresent Then
                                    Dim hrEFFDT As Date = Date.Parse(csentry("EFFDT").Value)

                                    If hrEFFDT <= Date.Today.AddDays(2) Then
                                        mventry("Terminated").Value = "true"
                                    Else
                                        mventry("Terminated").Value = "false"
                                    End If

                                Else
                                    'Status = Anything but 'T' or 'L'
                                    mventry("Terminated").Value = "false"
                                End If
                            End If
                        Else
                            mventry("Terminated").Value = "true"
                        End If 'End of checking for status not null
                    Else
                        mventry("Terminated").Value = "true"
                    End If 'End of checking for quick terms

    Wednesday, August 7, 2013 2:57 PM
  • Try something like this:

    If mventry("QuickTerm").IsPresent Then

      If mventry("OuickTerm").Value = "true" Then

         ' do true logic

      Else

        ' do false logic, assuming bool attribute

      End If

    Else

      ' do not present logic

    End If

    Mark


    Mark Creekmore - BlueVault Software http://www.bluevaultsoftware.com

    Wednesday, August 7, 2013 3:03 PM