Hi,
I am using below code for generating Unique AccountName but it is not working proper for me,it is working for existing Users but not work for New Users.and giving below Error please help on this.
Microsoft.MetadirectoryServices.AttributeNotPresentException: Attribute "firstName" is not present.
at Microsoft.MetadirectoryServices.Impl.AttributeImpl.get_Value()
at Mms_ManagementAgent_SQLMAExtension.MAExtensionObject.GetCheckedMailNickName(String AccountName, MVEntry mventry) in C:\Users\Administrator\Desktop\SQLMAExtension\SQLMAExtension.cs:line 129
at Mms_ManagementAgent_SQLMAExtension.MAExtensionObject.Microsoft.MetadirectoryServices.IMASynchronization.MapAttributesForImport(String FlowRuleName, CSEntry csentry, MVEntry mventry) in C:\Users\Administrator\Desktop\SQLMAExtension\SQLMAExtension.cs:line
88
using System;
using Microsoft.MetadirectoryServices;
using System.IO;
namespace Mms_ManagementAgent_SQLMAExtension
{
/// <summary>
/// Summary description for MAExtensionObject.
/// </summary>
public class MAExtensionObject : IMASynchronization
{
public MAExtensionObject()
{
//
// TODO: Add constructor logic here
//
}
void IMASynchronization.Initialize()
{
//
// TODO: write initialization code
//
}
void IMASynchronization.Terminate()
{
//
// TODO: write termination code
//
}
bool IMASynchronization.ShouldProjectToMV(CSEntry csentry, out string MVObjectType)
{
//
// TODO: Remove this throw statement if you implement this method
//
throw new EntryPointNotImplementedException();
}
DeprovisionAction IMASynchronization.Deprovision(CSEntry csentry)
{
//
// TODO: Remove this throw statement if you implement this method
//
throw new EntryPointNotImplementedException();
}
bool IMASynchronization.FilterForDisconnection(CSEntry csentry)
{
//
// TODO: write connector filter code
//
throw new EntryPointNotImplementedException();
}
void IMASynchronization.MapAttributesForJoin(string FlowRuleName, CSEntry csentry, ref ValueCollection values)
{
//
// TODO: write join mapping code
//
throw new EntryPointNotImplementedException();
}
bool IMASynchronization.ResolveJoinSearch(string joinCriteriaName, CSEntry csentry, MVEntry[] rgmventry, out int imventry, ref string MVObjectType)
{
//
// TODO: write join resolution code
//
throw new EntryPointNotImplementedException();
}
void IMASynchronization.MapAttributesForImport(string FlowRuleName, CSEntry csentry, MVEntry mventry)
{
//
// TODO: write your import attribute flow code
//
switch (FlowRuleName)
{
case "UniqueID":
if (csentry["AccountName"].IsPresent)
{
// The value for the mailnickname attribute should be unique on every
// <tla rid="fim_syncdb_short" /> entry. To create a unique value, call a function that
// calculates a unique name based upon the connector space entry.
// Use this calculated value as the attribute value for the <tla rid="fim_syncdb_short" />
// entry.
string newMailNickname = GetCheckedMailNickName(csentry["AccountName"].Value, mventry);
//Logger(newMailNickname);
// If a unique nickname could not be created, throw an exception.
if (newMailNickname.Equals(""))
{
throw new TerminateRunException("A unique mailNickname could not be found");
}
mventry["AccountName"].Value = newMailNickname;
//Logger(newMailNickname);
}
else
{
mventry["AccountName"].Delete();
}
break;
default:
break;
}
}
void IMASynchronization.MapAttributesForExport(string FlowRuleName, MVEntry mventry, CSEntry csentry)
{
//
// TODO: write your export attribute flow code
//
throw new EntryPointNotImplementedException();
}
// This function creates a unique mailNickname for use in a <tla rid="fim_syncdb_short" /> entry.
string GetCheckedMailNickName(string AccountName, MVEntry mventry)
{
MVEntry[] findResultList = null;
//string checkedMailNickname = AccountName;
// Create a unique naming attribute by adding a number to
// the existing mailNickname value.
for (int nameSuffix = 1; nameSuffix < 100; nameSuffix++)
{
// Check if the mailNickname value exists in the <tla rid="fim_syncdb_short" /> by
// using the Utils.FindMVEntries method.
AccountName = mventry["firstName"].Value + mventry["lastName"].Value.Substring(0, nameSuffix);
string checkedMailNickname = AccountName;
findResultList = Utils.FindMVEntries("AccountName", checkedMailNickname, 1);
if (findResultList.Length == 0)
{
// The current mailNickname is not in use.
return (checkedMailNickname);
}
// If a <tla rid="fim_syncdb_short" /> entry was found with the specified mailNickname,
// see if this is the entry specified.
MVEntry mvEntryFound = findResultList[0];
if (mvEntryFound.Equals(mventry))
{
return (checkedMailNickname);
}
// If the passed nickname is already in use by another <tla rid="fim_syncdb_short" />
// entry, concatenate the counter number to the passed value and
// verify this new value exists. Repeat this step until a unique
// value is created.
//checkedMailNickname = AccountName + nameSuffix.ToString();
//Logger(checkedMailNickname);
}
// Return an empty string if no unique nickname could be created.
return "";
}
}
}
Regards
Anil Kumar
-
Edited by
AnilKumarIDM
Tuesday, November 18, 2014 10:48 AM