Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Erro get field custom using c#

Posted on by 684
Dears, good morning,

We are trying to read a custom field prefixed with new in the user table and I am getting the error below.

{"A entidade 'SystemUser' não contém o atributo com Name = 'new_cpf' e NameMapping = 'Logical'.


MetadataCacheDetails: ProviderType = Dynamic, StandardCache = True, IsLoadedInStagedContext = False, Timestamp = 170964232,


MinActiveRowVersion = 170964232, MetadataInstanceId = 23673480, LastUpdated = 2021-07-04 01: 28: 38.383 "}

Has anyone experienced a similar error? Can you help me?

Thanks

  • RE: Erro get field custom using c#

    Guido and Naveen good afternoon,

    We managed to get the field, the connection string of the homologation base was pointed to the Production base, for this reason the field was not displayed.

    Thanks for the support.

  • Willian Kupas Profile Picture
    Willian Kupas 10 on at
    RE: Erro get field custom using c#

    Hi Guido,

    In fact the entity "system user" did not have the field "new_cpf".

    This field was created in a test environment, and the scenario I was testing was set to production.

    Sorry for the inconvenience, and thanks for the help.

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: Erro get field custom using c#

    Hello Willian,

    Please share the screenshot of your field in CRM and as Guido mentioned, check the connection if it is with the right environment or not. I don't think there is any other issue

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,063 Moderator on at
    RE: Erro get field custom using c#

    the error is clear: there is no attribute named "new_cpf" inside systemuser entity. If this attribute exists please:

    1) post a screenshot of this attribute inside the entity designer

    2) make sure your connection is against the instance where this attribute is created (maybe you created just in DEV but the connection is against PROD)

    Now, the code of this function public static EntityCollection GetEntitySystemUser(string guidUser)

    if you pass a guidUser (and I assume it's an ID of the entity, you can just do the following:

    public static Entity GetEntitySystemUser(string guidUser) {
    try {
        Guid id = Guid.Parse(guidUser);
        return CRMContext.Service.Retrieve("systemuser", id, new ColumnSet("new_cpf"));
    } catch (Exception ex) {
        string errorMessage = ex.Message;
        return null;
    }
    }

    of  course the above code is based on your code, in other conditions the code should be written in a different way.

  • Willian Kupas Profile Picture
    Willian Kupas 10 on at
    RE: Erro get field custom using c#

    Hi Naveen how are you?

    I'm the developer working on this project with Ricardo.

    I tested the plugin with your code but got the same error. The field is properly filled out.

  • RE: Erro get field custom using c#

    Hola Naveen,

    Thanks for the feedback, I'll test and let you know if I managed to get the field value

    Tanks

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: Erro get field custom using c#

    Hi Ricardo,

    try this

    public static EntityCollection GetEntitySystemUser(string guidUser)
    
            {
    
                var criteria = new FilterExpression();
    
                criteria.AddCondition("systemuser", "systemuserid", ConditionOperator.Equal, guidUser);
    
                QueryExpression query = new QueryExpression("systemuser");
                
                 var columnNames = new[] { “new_cpf” };
    
                query.ColumnSet = new ColumnSet(columnNames);
    
                query.Criteria = criteria;
    
                return CRMContext.Service.RetrieveMultiple(query);
    
            }

    Hope it will be helpful 

  • RE: Erro get field custom using c#

    Good afternoon Naveen Ganeshe,

    The field is correct with its respective name

    Here's the code we're using.

    public static EntityCollection GetEntitySystemUser(string guidUser)

            {

                var criteria = new FilterExpression();

                criteria.AddCondition("systemuser", "systemuserid", ConditionOperator.Equal, guidUser);

                QueryExpression query = new QueryExpression("systemuser");

                query.ColumnSet = new ColumnSet("new_cpf");

                query.Criteria = criteria;

                return CRMContext.Service.RetrieveMultiple(query);

            }

    A detail is that the field only appears when the value is filled.

    We also use query.ColumnSet = new ColumnSet(true); to bring up all fields, but even so the new custom field didn't come.

    Thanks

  • Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: Erro get field custom using c#

    Hello Ricardo,

    Please make sure you have the correct field name(new_cpf) from the user entity. This is what the error says.

    Also, Please share that retrieving code line here for more info

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans