#1 2025-01-19 10:21:36

johnnysynop
Member
Registered: 2018-07-01
Posts: 39

get custom attr does not work

How to display any attribute value?

Uinfo: TLdapUser;
WriteLn('ID: '+(UInfo.custom( 'EmployeeID')));

return just nothing (field is not empty)

Offline

#2 2025-01-19 12:26:11

johnnysynop
Member
Registered: 2018-07-01
Posts: 39

Re: get custom attr does not work

ab wrote:

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

#3 2025-01-19 15:27:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,791
Website

Re: get custom attr does not work

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

#4 2025-01-19 20:30:52

johnnysynop
Member
Registered: 2018-07-01
Posts: 39

Re: get custom attr does not work

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 (Yesterday 07:30:32)

Offline

#5 Yesterday 07:40:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,791
Website

Re: get custom attr does not work

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

#6 Yesterday 09:04:00

johnnysynop
Member
Registered: 2018-07-01
Posts: 39

Re: get custom attr does not work

ab wrote:

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 (Yesterday 09:19:14)

Offline

#7 Yesterday 10:17:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,791
Website

Re: get custom attr does not work

So what is wrong with TLdapClient.GetUserInfo() and ['windowsUser'] as CustomAttributes parameter?

Offline

#8 Yesterday 11:23:45

johnnysynop
Member
Registered: 2018-07-01
Posts: 39

Re: get custom attr does not work

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 (Yesterday 15:35:42)

Offline

#9 Yesterday 16:56:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,791
Website

Re: get custom attr does not work

    GetUserInfo('windowsUser', '', '', u, '', false, ['EmployeeID']);
    writeln(u.Custom('EmployeeID'));

works on my side.

Offline

Board footer

Powered by FluxBB