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 ?
Related
When a user sets the "Scope" on an Opportunity record to "Parent Opportunity", a grid appears that allows the user to create child Opportunity records associated with the parent. I am trying to create a web resource for an OnLoad event that will auto-populate the Opportunity Name, Contact, and Account of the QuickCreate form with the data that is in the Parent Opportunity form. Account and Contact are lookups to separate entities, and Opportunity Name is a text field. Here is what I have so far:
function SetLocalStorage(executionContext)
{
var formContext = executionContext.getFormContext();
var account = formContext.getControl("ParentAccountId").getAttribute().getValue();
var contact = formContext.getControl("ParentContactId").getAttribute().getValue();
var oppname = formContext.getControl("new_name").getAttribute().getValue();
localStorage.setItem("Account", account);
localStorage.setItem("Contact", contact);
localStorage.setItem("OpportunityName", oppname);
}
I am fairly new to JavaScript and am not really sure what to add to the web resource in order for the QuickCreate form to auto-populate. Any help would be greatly appreciated.
Thanks!
I would propose Codeless solution. Dynamics 365 already provides out of box feature for the same requirement.
For sake of explanation, I have taken Account and Contact Entity.
So from Account If I want to create Contact, few of information shall be autopopulated as shown in Image below.
Now how do I do this. There is 1:N relationship from Account to Contact. So in your case there will be 1:N relationship from Opportunity to Scope. Just like below image
Now when you go inside relationship you will have mapping. What this mapping does it copy data from Source to Target fields. In my case I have few fields been mapped from Account to contact. You can do the same and this will solve your issue.
I'm basically trying to create a primary ID between CRM and QuickBooks. Figured I'd just use the existing PK in CRM for the lookup. I'd like the PK to visible to the user, but not editable in CRM.
This has presented several problems in that you can't do that out of the box. I thought I read somewhere you could either via business rule or calculated field, but I haven't had luck with that.
It sounds like it would require web resources if I were to go this route.
The other option would be to just generate unique values for every record in Accounts and Contacts.
Does this automatically populate existing records or just new records? How do I get it to populate existing records?
You can use Auto number manager for configuring an auto-number attribute in every entity. This seeds a number based on configured format for new records. Uniqueness assured by SQL sequence feature & no need of any extra plugin/workflow.
For existing records - you can design a workflow along with a temp entity to assign auto-number. Read more.
Otherwise you can use SSIS + Kingswaysoft package to generate auto-number & assign for existing records.
I am suggesting you to create a new text field on the entity and create a pre plugin that will get the record primary GUID id from context and will set this GUID into the newly added attribute. You can set this field as read-only of form as well.
OR you can generate new GUID as well into the plugin.
I'm trying to update the OwnerId on an opportunity in Dynamics CRM 2015.
So far I am using the following code but my changes are not taking effect.
Xrm.Page.data.entity.attributes.get('ownerid').setValue('487ecd0c-d8c1-e411-80eb-c4346bade4b0')
Xrm.Page.data.entity.save();
This is a view of the GetValue call.
The attribute type is "lookup" and when I call getIsDirty(), it returns false after I do setValue, so I'm not sure if that's the correct way to set the value on a "lookup" type.
Owner is a special field, it can be changed only with an AssignRequest.
With CRM Online Update 1 this changed, special fields like Owner or StateCode can be updated with an update request, but as far as I know this is valid from server side, for client side changes you will still need to use an AssignRequest.
Here a sample code:
Using Assign Requests to Assign Entities to a User Using Jscript and .NET in Microsoft Dynamics CRM 2011
EDIT:
Just for reference, this is the way to set a lookup field
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}';
lookup[0].name = 'Test Account';
lookup[0].entityType = 'account';
Xrm.Page.getAttribute("new_account").setValue(lookup);
or short version
Xrm.Page.getAttribute("new_account").setValue([{ id: '{487ecd0c-d8c1-e411-80eb-c4346bade4b0}', name: 'Test Account', entityType: 'account'}]);
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.
In the Spring/Hibernate/Java/Tomcat app I'm writing I have a OneToMany relationship between an Organization and its Contacts.
Organization 1:M Contact (has foreign key org_id)
In Organization I have this field:
#OneToMany(mappedBy="organization")
private List<Contact> contacts;
In Contact I have this field:
#ManyToOne
#JoinColumn(name="org_id")
private Organization organization;
All is working OK so far. Now I'm adding the concept of an Offer. The Offer can be made by an Organization, and you speak with the designated Contact for that particular Offer.
Offer has foreign keys for its organization (org_id) and designated contact (contact_id).
So far, the Offer would look like:
#OneToOne
#JoinColumn(...)
private Organization offering_org;
#OneToOne
#JoinColumn(...)
private Contact offering_contact;
Here comes the point of my question. I've already annotated the Contact class for use with Organization. If I try to persist the Offer object in the usual Hibernate way, I'll need to store copies of an Organization object and a Contact object into the Offer object. This seems to conflict with my existing Organization : Contact use of the two Java classes. For example, if I've a 1:1 with Offer, if I put this into the Contact class do I get an optional use of either or a mandatory simultaneous use of both?
Since the Offer is yet another relationship, do I need to write a data transfer object version of Contact for use in the Offer relationship?
Thanks,
Jerome.
Perhaps I do not fully understand the problem but I'd just do something like this:
// contact & organization being already persisted entity objects
Offer offer = new Offer();
offer.setOffering_org(organization);
offer.setOffering_contact(contact);
// Persisting the new Offer object to the database,
// implicitly making the relations.
service.saveObject(offer);
I see no reason to create copy(s) of the organization object?
It just happens to be that the collection of "contacts" in the Organization object can also be a Contact within one or more Offer objects.
I'm thinking that my original question is kind of stupid. What I did try is to put this in Offer.java:
#Column(name="org_id")
private Long orgId = null;
#Column(name="contact_id")
private Long contactId = null;
I fill orgId manually because an offer is always tied to the user's Organization. It is a hidden field in the web page.
I put a SELECT filled with appropriate Contact objects (contact.id, contact.name) in the web page.
When the web page is submitted the Offer's orgId and contactId fields are filled in the #ModelAttribute parameter. This takes me where I want to go.
To address the comments of Mr. mspringer, your example could work (you illustrated a "create new" situation) if I were willing to use an Organization or Contact list in my Offer object. It is also somewhat the topic of my original question. But since I see that I don't really want to play with the expanded objects within Offer, nor do I wish to, I can avoid the topic of my original question.
Thanks to all who looked at my exercise in confusion.