How to get client's contact details in lync sdk c# - botframework

Which Object has the client contact information like office,company,IM, etc,. in Lync SDK 2013? I want to know the user's(client's) location/address information.

User location/office information can be obtained from contact object as given below:
LyncClient lyncClient = LyncClient.GetClient();
Contact contact = lyncClient.ContactManager.GetContactByUri("sip:contact#organization.com");
String officeLocation = contact.GetContactInformation(ContactInformationType.Office).ToString();
More information can be obtained using Contact information types Personal Note, Company, Location, Department etc.

In addition to Kannan's answer, getting the phone numbers from a contact is different and requires more work. Here's how you do it:
LyncClient lyncClient = LyncClient.GetClient();
Contact contact = lyncClient.ContactManager.GetContactByUri("sip:contact#organization.com");
List<object> endPoints = new List<object>();
var telephoneNumber = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
endPoints = telephoneNumber.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone || ((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone || ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
foreach (var endPoint in endPoints)
{
//((ContactEndpoint)endPoint).DisplayName.ToString(); //This is the phone number in string format
}

Related

Get specific CRM organization instead of all

There are multiple organizations on a CRM on-prem environment. I have stored DiscoveryService URL and organization name in a configuration file.
I want to get an Organization instance for a specific organization using organization name available in the configuration file, instead of loading all organizations.
something similar to,
select organizations from Organizations where orgName = 'XYZ'
Currently, I am using the below code, which is taking more than 3 seconds to retrieve an instance.
private OrganizationDetail DiscoverOrganization(Uri discoveryUri, string organizationName, ClientCredentials lclClientCredentials)
{
DiscoveryServiceProxy serviceProxy;
using (serviceProxy = new DiscoveryServiceProxy(discoveryUri, null, lclClientCredentials, null))
{
IDiscoveryService service = serviceProxy;
var orgsRequest = new RetrieveOrganizationsRequest() { AccessType = EndpointAccessType.Default, Release = OrganizationRelease.Current };
var organizations = (RetrieveOrganizationsResponse)service.Execute(orgsRequest);
return organizations.Details.FirstOrDefault(x => x.UniqueName.ToLower() == organizationName.ToLower());
}
}
You can try web api version as well. Read more
GET https://dev.{servername}/api/discovery/v9.0/Instances(UniqueName='myorg')

Check if current user is a member of exchange distribution list - Outlook C#

I want to find out if current Outlook user is a member of particular exchange distribution list. If he is, then he should see child form and if he isn't; then he should see message box.
My following code is working up to the point, if user is a member of DistList, he get child form but I don't know how to check show him message box if he isn't member.
string UserName = (string)application.ActiveExplorer().Session.CurrentUser.Name;
string PersonalPublicFolder = "Public Folders - " + application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;
Outlook.MAPIFolder contactsFolder = outlookNameSpace.Folders[PersonalPublicFolder].Folders["Favorites"];
Outlook.DistListItem addressList = contactsFolder.Items["ContactGroup"];
if (addressList.MemberCount != 0)
{
for (int i = 1; i <= addressList.MemberCount; i++)
{
Outlook.Recipient recipient = addressList.GetMember(i);
string contact = recipient.Name;
if (contact == UserName)
{
var assignOwnership = new AssignOwnership();
assignOwnership.Show();
}
}
}
Any help would be appreciated.
Thank you.
Use Application.Session.CurrentUser.AddressEntry.GetExchangeUser().GetMemberOfList() - it will return AddressEntries object that contains all DLs that the user is a member of.
Be prepared to handle nulls and errors.

Automatically map a Contact to an Account

I want to add a field to Accounts which shows the email domain for that account e.g. #BT.com. I then have a spreadsheet which lists all the Accounts and their email domains. What I want to do is when a new Contact is added to Dynamics that it checks the spreadsheet for the same email domain (obviously without the contacts name in the email) and then assigned the Contact to the Account linked to that domain. Any idea how I would do this. Thanks
Probably best chance would be to develop CRM plugin. Register your plugin to be invoked when on after contact is created or updated (so called post-event phase). And in your plugin update the parentaccountid property of the contact entity to point to account of your choice.
Code-wise it goes something like (disclaimer: not tested):
// IPluginExecutionContext context = null;
// IOrganizationService organizationService = null;
var contact = (Entity)context.InputParameters["Target"];
var email = organizationService.Retrieve("contact", contact.Id, new ColumnSet("emailaddress1")).GetAttributeValue<string>("emailaddress1");
string host;
try
{
var address = new MailAddress(email);
host = address.Host;
}
catch
{
return;
}
var query = new QueryExpression("account");
query.TopCount = 1;
// or whatever the name of email domain field on account is
query.Criteria.AddCondition("emailaddress1", ConditionOperator.Contains, "#" + host);
var entities = organizationService.RetrieveMultiple(query).Entities;
if (entities.Count != 0)
{
contact["parentaccountid"] = entities[0].ToEntityReference();
}
organizationService.Update(contact);
I took Ondrej's code and cleaned it up a bit, re-factored for pre-operation. I also updated the logic to only match active account records and moved the query inside the try/catch. I am unfamiliar with the MailAddress object, I personally would just use string mapping logic.
var target = (Entity)context.InputParameters["Target"];
try
{
string host = new MailAddress(target.emailaddress1).Host;
var query = new QueryExpression("account");
query.TopCount = 1;
// or whatever the name of email domain field on account is
query.Criteria.AddCondition("emailaddress1", ConditionOperator.Contains, "#" + host);
query.Criteria.AddCondition("statecode", ConditionOperator.Equals, 0); //Active records only
var entities = organizationService.RetrieveMultiple(query).Entities;
if (entities.Count != 0)
{
target["parentaccountid"] = entities[0].ToEntityReference();
}
}
catch
{
//Log error
}

Can Dynamics Crm PartyList store an emailaddress

I have fields in activity form for email. It contains "to, cc and bcc" fields that are all fields of the type PartyList
The question is: Can I only store entity values like contact or account or can I also just store a email address which is not associated to any contact or account in the system?
Here is a picture explaining what I'm trying to achieve
As per this article it appears that the answer is yes via the addressUsed field.
Entity email = _sdk.Retrieve("email", emailId, new ColumnSet("to"));
EntityCollection to = email.GetAttributeValue<EntityCollection>("to");
if (to != null)
{
to.Entities.ToList().ForEach(party =>
{
EntityReference partyId = party.GetAttributeValue<EntityReference>("partyid");
bool isDeleted = party.GetAttributeValue<bool>("ispartydeleted");
string addressUsed = party.GetAttributeValue<string>("addressused");
// Do something...
});
}

How to call dynamic crm 2016 rest api from javascript?

I want to create lead in dynamic crm from my website. My website is build using HTML as this is a static site. I need to call dynamic crm (setup on premises) api from contact us page to submit data in dynamic crm.
Please suggest me a right direction.
Thanks
The SDK has lots of helpful information, have you looked at it? Here's a start:
Authenticating to CRM from JS using adal.js
Perform operations using the Web API
This is a sample code we use to submit entries from webpage to CRM. Hope this helps:
function CreateWebLeadInCRM(SourceCampaignName, Email, MobilePhone, FirstName, LastName, CompanyName){
var webLead = new Object();
//Add Source Campaing name
if(SourceCampaignName != null)
webLead.sof_sourcecampaign = SourceCampaignName;
//Add Email
if(Email != null)
webLead.sof_Email = Email;
//Add Mobile phone
if(MobilePhone != null)
webLead.sof_MobilePhone = MobilePhone;
//Add First name
if(FirstName != null)
webLead.sof_FirstName = FirstName;
//Add Last name
if(LastName != null)
webLead.sof_LastName = LastName;
//Add Company name
if(CompanyName != null)
webLead.sof_CompanyName = CompanyName;
var jsonwebLead = JSON.stringify(webLead);
var createwebLeadReq = new XMLHttpRequest();
createwebLeadReq.open("POST", "http://SERVER/ORG/XRMServices/2011/OrganizationData.svc/sof_webleadSet", true, "USERNAME", "PASSWORD");
createwebLeadReq.setRequestHeader("Accept", "application/json");
createwebLeadReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
createwebLeadReq.onreadystatechange = function () {
createwebLeadReqCallBack(this);
};
createwebLeadReq.send(jsonwebLead);
Ugly thing about this approach is that you have to save your password inside your javascript function, which is not really safe approach.. On the other hand you should only allow this user to insert entries to only one custom table without possibility to do anything else inside your CRM. This way you could manage what happens if you get spammed by the bots.

Resources