You are not logged in.
Pages: 1
How to display any attribute value?
Uinfo: TLdapUser;
WriteLn('ID: '+(UInfo.custom( 'EmployeeID')));
return just nothing (field is not empty)
Offline
Don't put JSON in-between.
LDAPProperties := LDAP.SearchAll([], ObjectFilter(ofUsers, windowsUser), [roCanonicalNameAtRoot, roSortByName, roSddlKnownUuid, roAutoRange, roKnownValuesAsArray]); ... EmployeeID := LDAPProperties.EmployeeID;
@ab, I found your this snippet from other post .
what data types for EmployeeID and LDAPProperties you mean there? I mean var declarations.
Beside datatype question, what is the most proper way to get any single attribute (not listed in ldapuser)?
Last edited by johnnysynop (2025-01-19 12:53:54)
Offline
TLdapClient.SearchAll() returns a variant.
This will be a TDocVariant.
If you want a single attribute, just specify a single so* enum in the TLdapAttributeTypes set.
If you want to specify the attributes as text (e.g. if it is not any TLdapAttributeTypes enum) , you can use TLdapClient.SearchAllDocRaw() or SearchAllRaw().
Offline
thx, I set
var LDAPProperties :variant:= LDAP.SearchAll([], ObjectFilter(ofUsers, windowsUser), [roCanonicalNameAtRoot, roSortByName, roSddlKnownUuid, roAutoRange, roKnownValuesAsArray]);
var EmployeeID:utf8string := LDAPProperties.EmployeeID;
Writeln('EmployeeID: ', EmployeeID);
compiles well but on runtime gives me error:
Could not convert variant of type (Null) into type (String)
but this attribute for that user sure has value I confirmed with windows attribute editor...
Last edited by johnnysynop (2025-01-20 07:30:32)
Offline
What actually do you want to do?
The fact that you have the "Could not convert variant of type (Null) into type (String)" error has nothing to do with mORMot, it is your query which returns no result.
You did not define any "EmployeeID" attribute, so of course there is no EmployeeID field value, so LDAPProperties.EmployeeID returns null.
If you want to have the attribute value of one object, and are lost with variants, don't use SearchAll() but just SearchObject().
Then use TLdapResult.Attributes.GetByName().
Something like that:
EmployeeID := LDAP.SearchObject(DN, Filter, ['EmployeeID']).Attributes.GetByName('EmployeeID');
Offline
What actually do you want to do?
I want get single attribute value (employeeId) (not listed in TLdapUser properties) for chosen user in this case "windowsUser" var.
and I thought function Custom(const AttributeName: RawUtf8): RawUtf8; is for that from TLdapUser
or that I can extract it with
var EmployeeID:utf8string := LDAPProperties.EmployeeID;
Last edited by johnnysynop (2025-01-20 09:19:14)
Offline
I'm not sure if you understand me
your earlier code
EmployeeID := LDAP.SearchObject(DN, Filter, ['EmployeeID']).Attributes.GetByName('EmployeeID');
gives me AV
Can you please provide sample code, which works for you to get value of EmployeeID attribute for ldap user 'windowsUser'?
I know it sounds trivial for you but I want to make sure that we have consistent result, I mean my AD, Delphi, mormot etc.
Last edited by johnnysynop (2025-01-20 15:35:42)
Offline
thx, but I still wonder how it works for you if you copy/pasted it.
Second ver works for me good.
LdapClient.GetUserInfo('windowsUser', '', '', info, '', false, ['EmployeeID']);
writeln('Non 1:1 case sensitive, DOES NOT WORK');
writeln(info.Custom('EmployeeID'));
LdapClient.GetUserInfo('windowsUser', '', '', info, '', false, ['employeeID']);
writeln('1:1 with attribute name from LDAP, WORKS PERFECT');
writeln(info.Custom('employeeID'));
readln;
Very interesting, maybe your AD has different naming or you just pased it without really running
Anyway maybe some adding some new beside current very strict function would be useful?
I mean to get custom attr name but do not care about case-sens.
So it could not work from the begening due to "E" instead of "e". No matter what code would be used Thank you.
Last edited by johnnysynop (Yesterday 14:58:57)
Offline
LDAP attribute names are case sensitive AFAICT.
interesting, hmm:
https://stackoverflow.com/a/29908970
Offline
Ok got it, so AD username can be LiKeThAt, and will work but to get specific attribute strict naming needed.
All clear, thx Arnaud.
Offline
Pages: 1