This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Policy to check vale

Hi all,

is there a way to properly set a policy for a given value being digits?

I successfully set the policy to validate an attribute saying "must be: {4 required [0-9} which is working fine. However, I also need to check that there is no 0 in the beginning.

Actually it would need to be a value containing 4 digits between 0 and 9, larger than 999 and smaller than 10000 without a leading zero so everything between 1000 and 9999.

Parents
  • I managed to accomplish what I was looking for by not validating with the wizard but by running a script doing the validation.

    For the records:

     
      
     function checkPGiPIN($Request) 
    {    
        $Attribute = $Context.Parameter("Attribute1")    
        if ($Attribute -ne "Unused") 
        {        
            try { $Value = $Request.Get($Attribute) } catch { $Value='' }        
            if (($Value -ne '') -and ($Value -ne $null)) 
            {            
                $Result = $value -match "^([1-9][0-9][0-9][0-9])$"
                if ($Result -ne "True") 
                {                 
                    $AttribDesc = $Context.Parameter("Attribute1Desc")                
                    throw "Administrative Policy: $AttribDesc $Value is not in the right format. PIN should be greater than 999 and less than 10000"            
                }        
            }
        }            
    	
      
       
        return "OK"                
    }
    
    function onPreCreate($Request)
    {
        $return = checkPGiPIN($Request)
    }
    
    function onPreModify($Request)
    {
        $return = checkPGiPIN($Request)
    }
    
    function onInit($context)
    {
        $var = $context.AddParameter("Attribute1")
        $var.DefaultValue = "Unused"    
        $var.Description = "LDAP displayname of attribute #1 for which to check uniqueness"    
        $var.MultiValued = $false    
        $var.Required = $true        
        $var = $context.AddParameter("Attribute1Desc")    
        $var.DefaultValue = "Unused"    
        $var.Description = "Description of attribute #1 for which to check uniqueness"    
        $var.MultiValued = $false    
        $var.Required = $true    
    }
    

Reply
  • I managed to accomplish what I was looking for by not validating with the wizard but by running a script doing the validation.

    For the records:

     
      
     function checkPGiPIN($Request) 
    {    
        $Attribute = $Context.Parameter("Attribute1")    
        if ($Attribute -ne "Unused") 
        {        
            try { $Value = $Request.Get($Attribute) } catch { $Value='' }        
            if (($Value -ne '') -and ($Value -ne $null)) 
            {            
                $Result = $value -match "^([1-9][0-9][0-9][0-9])$"
                if ($Result -ne "True") 
                {                 
                    $AttribDesc = $Context.Parameter("Attribute1Desc")                
                    throw "Administrative Policy: $AttribDesc $Value is not in the right format. PIN should be greater than 999 and less than 10000"            
                }        
            }
        }            
    	
      
       
        return "OK"                
    }
    
    function onPreCreate($Request)
    {
        $return = checkPGiPIN($Request)
    }
    
    function onPreModify($Request)
    {
        $return = checkPGiPIN($Request)
    }
    
    function onInit($context)
    {
        $var = $context.AddParameter("Attribute1")
        $var.DefaultValue = "Unused"    
        $var.Description = "LDAP displayname of attribute #1 for which to check uniqueness"    
        $var.MultiValued = $false    
        $var.Required = $true        
        $var = $context.AddParameter("Attribute1Desc")    
        $var.DefaultValue = "Unused"    
        $var.Description = "Description of attribute #1 for which to check uniqueness"    
        $var.MultiValued = $false    
        $var.Required = $true    
    }
    

Children
No Data