I need to retrieve the entities from my CRM site and all the fields associated with that entity. Need to get the translated values as well.
Please provide some queries that will be helpful in this case
I tried with below queries, but this could not fetch all the values.
..../api/data/v9.1/EntityDefinitions(LogicalName='account')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
..../api/data/v9.1/EntityDefinitions(LogicalName='account')/Attributes
..../api/data/v9.1/GlobalOptionSetDefinitions
You can retrieve CRM entities by calling:
[Organization URI]/api/data/v9.1/
In order to get an entity's attributes you can call:
[Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='[Entity name (ex: account)]')/Attributes
For attribute translation, navigate to 'DisplayName' you will find 'LocalizedLabels'.
For more information you can check this url:
https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-metadata-web-api
I am trying to update value of codename field on Campaign entity but it wont let me do.
In C# code if I debug, I can see it goes through without any error and saves everything else except codename value.
On CRM form it is read only field and if I try to amend it and change value from 12345 to 12345678 for example it does not save.
Any idea what might be preventing it? When I create a new record I can add any value I like.
Your observations are correct: codename on Campaign can be set when creating a record but cannot be updated.
This information can be seen in the CRM SDK.
See campaign.codename in the CRM 4.0 SDK:
Valid for create: Yes
Valid for retrieve: Yes
Valid for update: No
I wrote a script (VBScript) to create/update CRM users based on an external MySQL database. Everything works great except for automatically setting the user's manager. In the MySQL database, each user has a unique ID and a reports_to field with the ID of his manager if any.
In the CRM, a custom field in the SystemUser table contains the unique user ID from the external table. This way, by looking at the external reports_to field I can link a CRM User to another. The worst part is that it actually works for some users, until it reaches one that brings an error: "The user is not in parent user's business hierarchy." Can someone explain me what this error is about ? I could not find any details or similar cases on the Internet.
I can manually set the Manager for this user in the CRM and it does not give me any error.
Here is my code:
Dim ManagerUser As New SystemUser
ManagerUser = GetUser("tld_id", clrint(User._reports_to), _serviceProxy)
If Not IsNothing(ManagerUser) Then
Dim ManagerId As Guid = ManagerUser.Id
Dim Manager = New SetParentSystemUserRequest
Manager.ParentId = ManagerId
Manager.UserId = _UserId
Manager.KeepChildUsers = True
_serviceProxy.Execute(Manager)
End If
Ok I found what it meant.
Some Business Units in the CRM are Parents from others. I was working with a DEV MySQL table (still test phase) that had unclean data. It resulted in some users having the wrong BU set.
Error was triggered when the manager belonged to a BU child from the user's one.
For integration purposes our users in Dynamics CRM need to have the same GUIDs as in the rest of our environment (several custom web apps built on ASP.NET and SQL Server 2005). But when we try to create a new Dynamics user with a certain GUID, Dynamics just ignores it and creates its own (the pattern of which leads me to believe that it’s using NEWSEQUENTIALID() internally, just as if the user was created through the UI). But for other types (contact for example) Dynamics takes the GUID with no issue.
Am I doing something wrong, or does Dynamics always ignore GUIDs on new user creation?
CrmService service = GetService();
systemuser newUser = new systemuser();
Key newUserId = new Key();
newUserId.Value = new Guid("D630FA8D-A32F-4a37-BFEF-CE36CBA29009");
// The GUID I would like Dynamics to use
newUser.systemuserid = newUserId;
Lookup bu = new Lookup();
bu.Value = new Guid("16B10365-0E18-DF11-B839-005056B60DD4");
// The correct business unit ID. Nothing to see here.
newUser.businessunitid = bu;
newUser.firstname = "John";
newUser.lastname = "Doe";
newUser.domainname = "DOMAIN\\jdoe";
// Valid AD credentials too. Names changed to protect the innocent.
Guid userId = service.Create(newUser);
Console.WriteLine("User created with GUID " + userId.ToString());
// Dynamics creates the user with a completely different GUID. :-(
Edit:
I've now asked this question on Microsoft's CRM forum as well.
I know it is not ideal, but as a workaround you could add a custom attribute to the systemuser entity and store your integration id there.
Without knowing more about your solution I can tell you that you don't need hardcoded quids everywhere like you are trying to do. When I arrived at my current client they were trying to do the same things and it was a serious PITA.
It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case) you want and then get the entity's id from that. No more trying to do something you should be trying to do in the first place.
It took me about a day to replace all the code that was using the hardcoded quids for various entities with a simple lookup procedure that gets the entity by whatever key (user name in your case)
How interesting. You're searchnig John Doe user by 'John','Doe' strings. And what should I do if I got TWO "John Doe" in my company ?
We have a Dynamics CRM 4.0 instance with some custom attributes of type "money" on the Case entity and on all Activity entities (Email, Phone Call, etc.) When I use the built-in "Convert Activity to Case" functionality I find that the resulting Case does not have a Currency set, even if the Activity it was created from does have it. Whenever the case is opened the user then gets this JavaScript error:
A currency is required if a value exists in a money field. Select a
currency and try again.
This is extremely annoying! How do I fix it? Is there any way I can set the currency? It needs to be done synchronously, because the Case is opened immediately when it's created from an Activity. So even if I started a workflow to set the currency the user would still get that error at least once. Alterntatively, can I just suppress the warning somehow? I don't really care about setting the Currency, I just want the error gone.
I guess this code will be helpful for next person who have a same problem.
I spent whole day to figure out what I did below.
There are two steps involved here:
set default currency
set currency symbol for the money field.
Here is the code sample.
var currency = crmForm.all.transactioncurrencyid;
if (currency.DataValue == null) {
var lookupData = new Array();
var lookupItem= new Object();
//Get transaction currency value from :
select **TransactionCurrencyId** from MSCRM.dbo.TransactionCurrency
lookupItem.id = '{The GUID that you get from the SELECT statement above}';
lookupItem.typename = 'transactioncurrency';
lookupItem.name = 'US Dollar';
lookupData[0] = lookupItem;
currency.DataValue = lookupData;
//set default currency symbol for all the Money field.
var defaultSymbol = '$';
for(var i=0; i < crmForm.all.length ; i++) {
var oCtr = crmForm.all[i];
if(!IsNull(oCtr.IsMoney) && !oCtr.IsBaseCurrency)
{
oCtr.CurrencySymbol = defaultSymbol;
}
}
}
This annoying issue was resolved on my system by discovering the transactioncurrencyid used for US dollars and then updating the transactioncurrencyid column in the entity's database table for all the existing entity records. After doing this I was able to add money values on the entity form with no further problems. Not sure if this solution would be ideal for everyone, but as I did not want to write code to do this and felt I shouldn't have to since if I added money attributes to a newly defined entity it didn't require writing code on my part to populate the transactioncurrencyid field - it just did it by default. So in summary, this problem only seems to occur if the the money fields are added to an existing entity that has existing data associated with it.
set default currency in Personalize Workspace, General tab
NEW records will use this currency
For EXISTING records (before money field(s) added) use Advanced Find to find records with NO currency value, then use Bulk Edit to set currency
You might want to check out this article CRM 4 Currency Calculations by Mitch Milam
Update : After googling around, i found out that you might need to set the transactioncurrencyid lookup somewhere. So in your case, it might be onsave or inside the execution of the workflow codes. I read it from here Error: Assign a decimal value to CRM 4.0 money field using Javascript
If your form has a money field on it, CRM needs to know which currency to use. Verify that a default currency is set in your user preferences (Personalize Workplace from the main page, then the General tab). That is, each of your users will need to have a default currency set.
I have also been able to work around this issue by adding the currency field to the form, defaulting it to US dollars, and then hiding the field. If memory serves, though, this isn't ideal because the US dollars currency is a record in the system and can have different GUIDs in different environments.
Since this thread came up in my Google search when I was looking for a solution to this problem for CRM 2011, I thought I'd add my blog article explaining how to set the default currency lookup in the Onload of a CRM 2011 form using JavaScript, JSON and OData.
http://crmscape.blogspot.com/2011/03/crm-2011-set-default-transaction.html
I agree with Hadi Teo that you need to set the transactioncurrencyid. Its been awhile since I ran across this - so here is what I think I remember.
If you create a new entity with a money field populated the transaction currency will be set.
If you update an entity, the transaction currency field will not be set.
I haven't used the Activity to Case function so I'm not all that sure what it does. One thing you can do as a work around is to add the transactioncurrencyid onto the form. Then you can set it before you modify your Case.
The other would be to default the currency in code. There are two places to determine the default currency. First off of the user settings. Second (if that is null) off of the organization settings.
Fix for this problem
1. Add the base currency field also to the form.
2. Untick the "visible by default option" of the base currency field.