Microsoft CRM: How to enable/disable Systemuser without deprecated SetStateRequest - c#

To disable a Dynamics CRM 2016 user with C# code the SetStateRequest is currently used.
Example:
var requestToDisableUser = new SetStateRequest()
{
EntityMoniker = new EntityReference("systemuser", userGuid),
State = new OptionSetValue(1),
Status = new OptionSetValue(-1)
};
organizationService.Execute(requestToDisableUser);
However, according to Microsoft the SetStateRequest is deprecated and should be replaced by using Update
But when I try to use Update to disable a user
Example:
var userToDisable = new Entity("systemuser", userGuid)
{
["statecode"] = new OptionSetValue(1),
["statuscode"] = new OptionSetValue(-1)
};
service.Update(userToDisable);
Then it raises the error :
Unhandled Exception:
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]:
'systemuser' entity doesn't contain attribute with Name =
'statecode'.
Which is true, because the systemuser Entity doesn't have a statecode.
And the systemuser Entity has a IsDisabled attribute, but that one is read-only.
So how can a user then be disabled/enabled without using SetStateRequest?

I don’t think it is possible, unless someone proves it is. To support my opinion: the latest SDK (8.2.1.1; 4/6/2017) still gives an example with SetStateRequest in SDK\SampleCode\CS\BusinessDataModel\UsersAndRoles\DisableOREnableUser.cs. Therefore, it should be the recommend way to do it, regardless the fact it is marked as deprecated in another part of documentation.
You might start an incident with MS support, or give suggestion on Connect; but according my experience, they don’t care much if workaround is available.

After CRM online 2015 update 1, special messages were deprecated for special attributes. Read more.
Per metadata, IsDisabled attribute of systemuser may be showing as not valid for update. And few other business owned entities like Team, BU, etc won't use statecode & statuscode.
You should be using IsDisabled attribute if planning to not to use deprecated methods.
It's probably a missing piece in documentation. But hints can be found wrt Specialized operations using Update message like below per MSDN
These specialized messages will continue to work with the 2011 endpoint. However, the recommendation is to use the UpdateRequest or Update method when possible to set these attributes. The Update message simplifies the Organization Service and makes it easier to code standard data integration tools used with Dynamics 365. In addition, it is easier to code and register a plug-in to execute for a single Update message instead of multiple specialized messages. The AttributeMetadata.IsValidForUpdate property for the above listed attributes has been changed to true in this release to enable this capability.
You can continue to use these specialized messages of the 2011 endpoint in your code. However, the Web API that eventually replaces the Organization Service supports only the Update message for these types of operations. If you want to get a head start on changing your code to align with the Web API, you can now do so. See Use the Microsoft Dynamics 365 Web API for more information.

Related

Dynamic CRM new fields

Some new fields were create in Dynamics CRM.
Now need to push some data to those new fields from asp.net website.
Need to add those new fields to:
[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]
namespace Xrm
how should this be done? I read that these is a tool that generates this class file (CrmSvcUtil.exe).
But I do not understand how this would work.
Is this something that need to be done through Dynamics CRM admin?
Please advise.
Thanks
This should be done by user which has System Administrator or System Customizer, because this user has to have access to all entities metadata.
Basically you should start with downloading CRM SDK, for your version of CRM. For example the latest SDK can be found here:
https://www.microsoft.com/en-us/download/details.aspx?id=50032
Install the SDK and go to the bin folder inside the folder where you installed it. There you can find crmsvcutil.exe. This tool is something like svcutil.exe - it simply generates proxy classes using CRM metadata service. So instead of referring to Account entity like that:
var account = new Entity("account")
you can simply do:
var account = new Account();
and you will have all the properties that account in your system has.
In order to generate this classes just run crmsvcutil.exe using windows command line with proper credentials (it's very well documented if you run it without any parameters). example usage would be:
crmsvcutil /url:https://orgname.api.crm4.dynamics.com/XRMServices/2011/Organization.svc /u:user#orgname.onmicrosoft.com /p:password /serviceContextName:XrmServiceContext /out:Proxies.cs /n:Xrm
this would generate file Proxies.cs, containing namespace Xrm (the one you have posted in your question) with all the entities and fields. Of course the parameters may vary based on what type of organization you are connecting to. If you have problems with specifying proper values then simply put /il as last command line parameter - it will open an interactive login form, that would make it simpler for you to pass proper connection data.

Microsoft Graph API not exposing certain properties

I've been looking into using the Graph API from Microsoft to monitor a few online Exchange inboxes.
I was reading their documentation here for Outlook Messages but I'm looking for conversationTopic. I know this is exposed in the normal Outlook Object Model; but I don't see it exposed in their documentation.
Has MS exposed this property in their API?
Info as of 9/15/2016
The conversationThread property has only been exposed in group conversations. It hasn't been exposed in a first class manner for a user's messages. This has been exposed on the beta endpoint via extended properties . You'll want to use the PidTagConversationTopic property.
Here's an example call to get this property (you'll just need to add your message id):
https://graph.microsoft.com/beta/me/messages('YOURMESSAGEID')?$expand=singleValueExtendedProperties($filter=id%20eq%20'String%200x0070')
Here it is for easier reading (no URL encoding):
https://graph.microsoft.com/beta/me/messages('YOURMESSAGEID')?$expand=singleValueExtendedProperties($filter=id eq 'String 0x0070')

Creating a lead programmatically in CRM Online

I have customized the lead entity in CRM for our business, is there a mechanism in CRM Online via the webservices that I can invoke to insert new records as a Lead in CRM from our local database? I cant find the correct details in Dynamics CRM Online's API. Please help!
Thanks. This is in C#.
Use the Simplified Connection
MS Dynamics CRM online 2011 - Authentication issues
and after create the records. The metadata of the Lead entity is here:
http://msdn.microsoft.com/en-us/library/gg334250(v=crm.5).aspx
Create your lead and define their attributes and save it
Entity lead = new Entity("lead");
// definition of lead attributes goes here
// lead.Attributes["xxxx"] = yyyy;
service.Create(lead);

Lync - inconsistent behavior with ContactEndpoints

I'm working on custom UI for company's directory based on Lync. Using Lync 2013 I execute this search:
Container.Instance.Lync.ContactManager.BeginSearch(SearchQuery,
SearchProviders.GlobalAddressList,
SearchFields.AllFields,
SearchOptions.IncludeContactsWithoutSipOrTelUri,
500,
ContactsAndGroupsCallback, SearchQuery);
For each of matching contacts I try to access their endpoints to display phone number:
var cit = ContactInformationType.ContactEndpoints;
var endpoints = contact.GetContactInformation(cit) as List<object>;
Problem
If found contact is in the contact list of account I'm using to connect Lync, then I get access to full details (5 endpoints). However if he is not in contact list, I get access to only 1 endpoint.
Any ideas why is it happening like that? Is there a global privacy setting I need to turn off or something?
How can I get access to all endpoints at all times?
Thank you.
PS: I tried to load each contact in the result set individually and still get the same behavior.
I encountered a similar problem when trying to write a program to obtain the status of all users on Lync SDK 2010. Chose all users and read it's status (online / offline etc.). But it's working out well with only those contacts that were in the list of client contacts. I do not know why, but the solutions are not found.A little later I use UCMA 4 (with Application endpoint), though the list received from AD and only able to get the current status.
Maybe it makes sense to use the search by AD? Find phone number by user sip? If so, try to use this filter for DirectorySearcher:
searcher.Filter = "(&(objectClass=user)(msRTCSIP-PrimaryUserAddress=*))"; //put sip instead of *
P.S. what sdk are you using?
Answer from Microsoft Support:
The behavior you are seeing is due to presence subscription optimization to the Lync client so that the subscription is delayed until the necessary contact information is required by the Lync client. Photo is an example for this optimization. Another example is ContactEndpoints. Please take a look at Contact presence subscription changes section of the Migration doc for Lync 2013 page in MSDN docs.
Specifically you must create and maintain your own ContactSubscription for the contacts that you need all the ContactEndpoints.
I have been facing the same issue. You can try loading the person's ContactCard before calling the GetContactInformation function explicitly
Microsoft.Lync.Controls.ContactCard objContactCard = new Microsoft.Lync.Controls.ContactCard();
objContactCard.Source=objContact.GetContactInformation(ContactInformationType.EmailAddresses);
ContactSubscription _contactSubscription = lyncObj.ContactManager.CreateSubscription();
_contactSubscription.AddContact(foundContact);
_contactSubscription.Subscribe(ContactSubscriptionRefreshRate.High, _ContactInformationList);
However, you still might get some delay in getting the information (phone numbers). You can choose to use Thread.Sleep or might just want to retry.
Hope this helps.
Problematic is relying on contact information even for the lync client user. In our solution we are doing something like this:
Contact user = LyncClient.GetClient().Self.Contact;
string email = user.GetContactInformation(ContactInformationType.PrimaryEmailAddress) as string;
I would expect that the current lync user contact always is filled properly. And if it wasn't, I'd expect the code to throw an exception or at least return null or an empty string.
Instead it sometimes returns the sip-uri of the contact without the leading "sip:" prefix. Oddly enough this is not always reproducable: Most of the time the code above returns the primary email address (according to active directory) correctly, sometimes it behaves as mentioned above.

Online CRM REST Service - Struck with an issue

This is a simple task, but i am wasting more than a day. Thats why coming to you. Please help me to get out of the issue.
My requirement is very simple, i have an ASP.NET project. And i have an Entity in Online CRM
Entity Name: "Employee" and Fields are "Name, Age, Gender"
I cann't add CRM Dlls in my asp.net project. So i must use REST Service.
I have added service reference https://myoffice.crm5.dynamics.com/xrmservices/2011/organization.svc?wsdl
This is the code i am using
OrganizationServiceClient orgClient = new OrganizationServiceClient();
orgClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("admin#something.com", "mypassword");
Entity myContact = new Entity();
myContact.LogicalName = "Employee"; //Is it right? i must provide it here right.
ConsoleApplication1.ServiceReference2.AttributeCollection myAttColl = new ConsoleApplication1.ServiceReference2.AttributeCollection();
myAttColl.Add(new KeyValuePair<string, object>("Name","Emp1"));
myAttColl.Add(new KeyValuePair<string, object>("Age", "26"));
myAttColl.Add(new KeyValuePair<string, object>("Gender", "Male"));
myContact.Attributes = myAttColl;
try
{
orgClient.Create(myContact);
}
catch (Exception ex)
{
}
I am getting "An error occurred when verifying security for the message" error when it run orgClient.Create(myContact).
No matter what i did so far. This is my requirement, a very simple adding entry to my custom entity into Online CRM using REST Service. I am going to run my webapplication in a separate domain called http://xyz.com. From here, i need to add the entries into Online CRM.
Any help?
It could seems strange but the reason is that the clock on the server and on the client are certainly not synchronized.
All you have to do is check that :
The client clock is synched with the server clock.
Both client and server are coordinated on the day time saving settings
Regards,
Kévin
Sources : here and here
The REST service is not exposed for external applications, it is for internal applications only. You may be able to get around this in an on premise deployment but in CRM Online there is no workaround that I am aware of. You are much better off if you add the CRM assemblies and do this in C#. Also, with the REST service you are severely limited to CRUD operations and you can't perform things like assign or change state. In my opinion the SOAP service is superior, but it still cannot be called from an external web application.
See the note that reads the following at this link - Data Access Using JavaScript
Note
It is not possible for an external application to use these web services because authentication is provided by Microsoft Dynamics CRM.

Categories

Resources