Select-field issue

Hi ,

I am using select-field with entity-find, entity-find returns the selected fields, but it also returns all the entity fields with null value.

Ideally entity-find should returns select fields only.

<entity-find entity-name="moqui.security.UserGroupMemberUser" list="groupUserList" cache="false">
    <date-filter/>
    <select-field field-name="userId,username,disabled"/>
    <use-iterator/>
</entity-find>

output

[[resetPassword:null, passwordHint:null, publicKey:null, locale:null, userGroupId:null, disabledDateTime:null, emailAddress:null, userId:EX_JOHN_DOE, hasLoggedOut:null, passwordSalt:null, passwordSetDate:null, passwordBase64:null, successiveFailedLogins:null, userFullName:null, timeZone:null, disabled:N, terminateDate:null, passwordHashType:null, thruDate:null, currentPassword:null, fromDate:null, currencyUomId:null, externalUserId:null, requirePasswordChange:null, ipAllowed:null, username:john.doe], [resetPassword:null, passwordHint:null, publicKey:null, locale:null, userGroupId:null, disabledDateTime:null, emailAddress:null, userId:EX_JOHN_DOE, hasLoggedOut:null, passwordSalt:null, passwordSetDate:null, passwordBase64:null, successiveFailedLogins:null, userFullName:null, timeZone:null, disabled:N, terminateDate:null, passwordHashType:null, thruDate:null, currentPassword:null, fromDate:null, currencyUomId:null, externalUserId:null, requirePasswordChange:null, ipAllowed:null, username:john.doe]]=

is there any way to get only select-field in output?

Select field only gets the data fields that are requested, and adds a null value for all the other fields.

You already are only getting the select-fields in the output.

The entity engine is returning an UserGroupMemberUser object, so of course the rest of the fields would be null. You Could switch to a custom entity if you wanted an object with just the relevant fields.

1 Like

The entity find isn’t returning null fields, it is the EntityValue object that knows about all of the fields on the entity so if you iterate over all keys you’ll get all fields, and those that don’t have a value from the database will be null.

The code you included didn’t show how you generated the output using the EntityList object from the entity-find operation. What you’re seeing is an artifact of printing the EntityValue object, not of what actually comes from the database or is stored internally in that EntityValue object (contained by the EntityList object).

1 Like

That’s a good point. Thanks for bringing that up!

Thanks for the details,
Let me re-review, will share the details soon

Found that the method EntityValue.getPlainValueMap is helpful here.

<entity-find entity-name="moqui.security.UserGroupMemberUser" list="groupUserList" cache="false">. 
    <date-filter/>
    <select-field field-name="userId,username,disabled"/>
    <use-iterator/>
</entity-find>

<iterate list="groupUserList" entry="userGroup">
    <log message="====== userGroup: ${userGroup.getPlainValueMap(0)} ========"/>
</iterate>

Above code produces result as

====== userGroup: [userId:EX_JOHN_DOE, _entity:moqui.security.UserGroupMemberUser, disabled:N, username:john.doe] ========
====== userGroup: [userId:EX_TLD, _entity:moqui.security.UserGroupMemberUser, disabled:N, username:example.ltd] ========
====== userGroup: [userId:EX_VIEWER, _entity:moqui.security.UserGroupMemberUser, disabled:N, username:example.viewer] ========

AND If we access the EntityValue object from the EntityList, then it returns all fields including null values.

<iterate list="groupUserList" entry="userGroup">
    <log message="====== userGroup: ${userGroup} ========"/>
</iterate>

Hope this helps.

Thanks

1 Like

Thank for the details David,

After reviewing EntityList found related method to get the value map.