I am working on a SQL to CRM copy data mapping. I want to either update an account record if it exists or insert a new one.
In CRM the accound_id GUID field is the primary key. I want to be able to look that up in CRM if it exists or generate a new one.
I think I am already generating one correctly:
SELECT
CAST(NULL as uniqueidentifier) AS ACCOUNTID,
A.VENDORACCOUNTNUMBER AS ACCOUNTNO,
11 AS ACCOUNTTYPE,
VENDORORGANIZATIONNAME AS LEGALACCOUNTNAME,
VENDORSEARCHNAME AS ACCOUNTNAME,
CURRENCYCODE AS CURRENCY,
DEFAULTDELIVERYTERMSCODE AS DELIVERYTERMS,
DEFAULTDELIVERYMODEID AS MODEOFDELIVERY,
CASHDISCOUNTCODE AS CASHTERMS,
DEFAULTPAYMENTTERMSNAME AS PAYMENTTERMS,
'YES' AS ISPRIMARY,
'BILL TO' AS ADDRESSPURPOSE,
A.ADDRESSDESCRIPTION AS BILLTONAME,
A.ADDRESSCOUNTRYREGIONID AS BILLTOCOUNTRY,
A.ADDRESSCOUNTYID AS BILLTOCOUNTY,
A.ADDRESSCITY AS BILLTOCITY,
A.ADDRESSSTATEID AS BILLTOSTATE,
A.ADDRESSSTREET AS BILLTOST,
A.ADDRESSZIPCODE AS BILLTOZIP,
A.FORMATTEDPRIMARYADDRESS AS BILLTOADDRESS,
PRIMARYPHONENUMBER AS BILLTOPHONE,
PRIMARYPHONENUMBERDESCRIPTION AS BILLTOPHONEDESC,
'199 - CORPORATE' AS DISTRICTNAME,
'f97564c6-93a1-e311-9696-6c3be5a8ce94' AS DISTRICT
FROM [dbo].[VendVendorV2Staging] A
WHERE A.ADDRESSLOCATIONROLES = 'Business';
What I don't know is how to look up a GUID if it exits or use a new one.
You have to configure an alternate key in CRM side for account entity, then you can do upsert (update if exists or else create) based on that key. Read more
If you don’t want do that, then you can always query the CRM and check for existence before create a new record based on some unique attribute like name, phone number or email.
You can use Additional column feature in ADF copy activity to generate a guild value column as shown below.
As Dynamics CRM supports Upsert, you can set the write behavior of your sink settings as Upsert and Ignore Null values as True as shown below. You can leave the alternate Key as empty if primary key is used (Define alternate keys for an entity - An alternate key is used to uniquely identify a record in Customer Engagement in place of the primary key).
And then map the AdditionalGuidColumn to the destination upsert column i.e., accound_id GUID field which is the primary key.
For additional info about Dynamics sink settings, please refer to this doc: Dynamics as a sink type
Related
In my project I want to set the user/team lookup field value in Test table with power automate flow.
But I want to not set directly field value, I have one field which is in Account table(Field Name is User) which is also user/team lookup field. I want to set, when the Account table lookup field is user then set field value(As Account Table User) in Test table and when the Account table field value is team then set the same field value(As Account Table Team) in Test table.
Actually when I add Account table look up field is User and I have added expression in user and team respectively it was show the error as below.
My Expressions are:
1.for User: if(empty(outputs('Get_Account_Details')?['body/_new_user_value']),concat('systemusers(',outputs('Get_a_row_by_ID_-_Get_Account_Owner')?['body/_parentsystemuserid_value'],')'),outputs('User_is_user'))
For Team: if(empty(outputs('Get_Account_Details')?['body/_new_user_value']),'',outputs('Team_is_team'),)
If I use above expression for User and Account table User(Field) is user then It's properly work but when I use both expressions it was not work.
Currently my Account table field is team then,
I got the team and not getting User which is Correct but when I set this compose in field output it getting the error.
Anyone Help?
you will need to find out entity schema name of field _new_user_value If it is systemuser then set as systemuser, if not it is Team
For a Field _new_user_value_ you will have option in power automate as Entity Name, check that if it is Team or user and based on it you can perfrom setting value.
I have no background in Microsoft Dynamics CRM and the company I'm at lost their one developer who was maintaining this system. There is a function app with some code I'm trying to understand. The intent of the code appears to be to determine the user who set a price discount to then either permit it or not. It gets the audit entities associated with the salesorder that contain a 115 in the CSV AttributeMask.
List<Audit> audit = myServiceContext.AuditSet.Where(a => a.ObjectId.Id == x.Id)
.ToList();
audit = audit.Where(a => a.AttributeMask.Split(',').ToList().Contains("115"))
.ToList();
I believe this 115 must represent the discount field, but I want to know where the past developer found this value.
I've found suggestions online for how to get these AttributeMask values with a name, like this one, from the stringmap table. I used XrmToolBox's FetchXML Builder to dump the entire table but it only goes from 0 through 113. Some suggest looking in MetadataSchema tables, but I can't find those tables, and saw suggestions that those are only available for on-premises CRM.
Where can I find the meaning of 115 and/or how did a past developer decide to use this value?
The code queries the Audit table and selects the audit rows for the record identified by objectid. (This is the first line.) As you can read on MS Docs column audit.attributemetadata contains a CSV of the ColumnNumber metadata property of attributes.
In the second line the audit rows are filtered down to those containing updates to column 115 of the table the targeted record belongs to. You can lookup the name and other properties of this column by retrieving the entity metadata for the table. The EntityMetadata object has an array of AttributeMetadata. In this array you can find the desired attribute by searching its column number in property ColumnNumber. More information can be found on MS Docs - AttributeMetadata.ColumnNumber Property.
I'm using the Dynamics connector in Azure Data Factory.
TLDR
Does this connector support loading child records which need a parent record key passed in? For example if I want to create a contact and attach it to a parent account, I upsert a record with a null contactid, a valid parentcustomerid GUID and set parentcustomeridtype to 1 (or 2) but I get an error.
Long Story
I'm successfully connecting to Dynamics 365 and extracting data (for example, the lead table) into a SQL Server table
To test that I can transfer data the other way, I am simply loading the data back from the lead table into the lead entity in Dynamics.
I'm getting this error:
Failure happened on 'Sink' side. ErrorCode=DynamicsMissingTargetForMultiTargetLookupField,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=,Source=,''Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Cannot find the target column for multi-target lookup field: 'ownerid'.
As a test I removed ownerid from the list of source columns it loads OK.
This is obviously a foreign key value.
It raises two questions for me:
Specifically with regards to the error message: If I knew which lookup it needed to use, how can I specify which lookup table it should validate against? There's no settings in the ADF connector to allow me to do this.
This is obviously a foreign key value. If I only had the name (or business key) for this row, how can I easily lookup the foreign key value?
How is this normally done through other API's, i.e. the web API?
Is there an XRMToolbox addin that would help clarify?
I've also read some posts that imply that you can send pre-connected data in an XML document so perhaps that would help also.
EDIT 1
I realised that the lead.ownertypeid field in my source dataset is NULL (that's what was exported). It's also NULL if I browse it in various Xrmtoolbox tools. I tried hard coding it to systemuser (which is what it actually is in the owner table against the actual owner record) but I still get the same error.
I also notice there's a record with the same PK value in systemuser table
So the same record is in two tables, but how do I tell the dynamics connector which one to use? and why does it even care?
EDIT 2
I was getting a similar message for msauto_testdrive for customerid.
I excluded all records with customerid=null, and got the same error.
EDIT 2
This link appears to indicate that I need to set customeridtype to 1 (Account) or 2 (Contact). I did so, but still got the same error.
Also I believe I have the same issue as this guy.
Maybe the ADF connector suffers from the same problem.
At the time of writing, #Arun Vinoth was 100% correct. However shortly afterwards there was a documentation update (in response to a GitHub I raised) that explained how to do it.
I'll document how I did it here.
To populate a contact with against a parent account, you need the parent accounts GUID. Then you prepare a dataset like this:
SELECT
-- a NULL contactid means this is a new record
CAST(NULL as uniqueidentifier) as contactid,
-- the GUID of the parent account
CAST('A7070AE2-D7A6-EA11-A812-000D3A79983B' as uniqueidentifier) parentcustomerid,
-- customer id is an account
'account' [parentcustomerid#EntityReference],
'Joe' as firstname,
'Bloggs' lastname,
Now you can apply the normal automapping approach in ADF.
Now you can select from this dataset and load into contact. You can apply the usual automapping approach, this is: create datasets without schemas. Perform a copy activity without mapping columns
This is the ADF limitation with respect to CDS polymorphic lookups like Customer and Owner. Upvote this ADF idea
Workaround is to use two temporary source lookup fields (owner team and user in case of owner, account and contact in case of customer) and with parallel branch in a MS Flow to solve this issue. Read more, also you can download the Flow sample to use.
First, create two temporary lookup fields on the entity that you wish to import Customer lookup data into it, to both the Account and Contact entities respectively
Within your ADF pipeline flow, you will then need to map the GUID values for your Account and Contact fields to the respective lookup fields created above. The simplest way of doing this is to have two separate columns within your source dataset – one containing Account GUID’s to map and the other, Contact.
Then, finally, you can put together a Microsoft Flow that then performs the appropriate mapping from the temporary fields to the Customer lookup field. First, define the trigger point for when your affected Entity record is created (in this case, Contact) and add on some parallel branches to check for values in either of these two temporary lookup fields
Then, if either of these conditions is hit, set up an Update record task to perform a single field update, as indicated below if the ADF Account Lookup field has data within it
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 got this error:
Error:Read-write mappings require an upsert field for syncing. Upsert fields must be defined as unique External ID fields in Salesforce.More Info...
Warning:Fields needed for insertion to Salesforce need to be mapped: LastName
after changing plan from Developer to Professional when creating mapping in Heroku for Contact object.
Even after chaning to plan higher than Professional, the same error appears.
It was possible with Developer plan.
When you do an Upsert operation, you can either specify the Salesforce record Id as the unique identifier, or you can specify a custom field. If you use a custom field, then that field must be marked as Unique inside Salsesforce. You can do this by going to Setup and editing the field. There's a checkbox to mark it as Unique and as an External Id.
Also, it looks like you're not populating all required fields, specifically: LastName on the Contact.