Jawad
Jawad

Reputation: 111

dynamics crm plugin retrieve related entity attributes value

i'm writing plugin to send sms to multiple users, the scenario is :

-i have a custom entity smsmessmage who has 1-N relationship with users entity when creating sms message, i need my plugin to extract from users entity a mobile phone for each user selected to send him sms.

any code sample will be helpful. thanks

Upvotes: 0

Views: 7344

Answers (2)

isaac
isaac

Reputation: 141

 var query = new QueryExpression("contact") {ColumnSet = new ColumnSet(true)};
                        query.Criteria.AddCondition("contactid", ConditionOperator.Equal, new Guid("user_id"));
                        var retrieveMultiple = service.RetrieveMultiple(query);
                        if (retrieveMultiple != null && retrieveMultiple.Entities != null && retrieveMultiple.Entities.Any())
                        {

//Do here

                        }

Upvotes: 0

Andrew Butenko
Andrew Butenko

Reputation: 5446

You can try to use following code:

Entity user = service.Retrieve("systemuser", userid, new ColumnSet("mobilephone"));
string mobilephone = user.GetAttributeValue<string>("mobilephone");

Where service is an instance of IOrganizationService you ca get in plugin and userid id identifier of a user to whom you need to send sms.

Upvotes: 2

Related Questions