Loading Lookup Data into Model Driven PowerApps Custom Entities - dynamics-crm

I am trying to upload 1000s of records into a custom entity on model driven Power Apps. I am able to read in text fields, option sets, dates, etc without any issue. However when I try to map lookup fields, I get an error that says "can't resolve the guid for the lookup field:...". I am able to select "Edit in Excel" in an entity where I can manually select the appropriate lookup choice. But i can not copy and paste the item name because it does not recognize it as a GUID. There is too much data to do this and I need a way to complete this in a programmatic way.
I essentially want to relate the Product IDs (500004, 500370, etc) to the POBs (POB-1000, POB-1001, etc), as records that I can connect together in the model driven app.
Error message after mapping fields and importing:

By default, while importing in CRM (aka Model driven Power App), Lookup field will expect either GUID of that record (ex. 78C03F0D-4618-41C6-9089-B5BDB456465A) or Name (Primary field of that entity record, ex. Full name) to resolve the particular record to be associated.
If you want to map another field, you can map it while doing mapping in Import wizard.
How To Set A Lookup Value With Non-Primary Field As Reference

Related

Document Template entity in Lookup field

I am trying to use a look field on my form which displays 'documenttemplate' entity's records. But since this is a system entity I'm unable to find it in the drop down menu of entities under Target Record Type.
I've looked for a PCF control for this but lookups are not yet supported by powerapps component framework.
So is there a way to show the documenttemplate data in the lookup field?

Loading records into Dynamics 365 through ADF

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

Generating unique IDs for new records and existing records

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.

How to auto-populate the look-up depends on the look up selected in Dynamic CRM?

I try using the workflow but it need to save the transaction before it populate, I try mapping it but doesn't work.
So I have a 3 Entities Expense,Vendor,Transaction.
In Vendor Entity I have a field of Vendor Name and a lookup field for Expense Category(Expense Entity).
In Transaction Entity I have a lookup for Vendor name and Expense Category, so when I select a vendor name in the lookup it will populate the lookup of expense category.
I already used the filter, yes it show the expense category depends on the vendor name selected, but the problem in there is I need to click the lookup field of expense tracker to show the value. I want is it will auto fill the lookup field without clicking it. Thank you
One of the way to achieve this is by using client side APIs. You may code something like that:
Upon vendor change:
Place a REST or Web API call to extract expense category ID and name
Populate the expense category lookup with category ID and name using client side XRM API
Another and much easier way is to create relationship mapping for expense category over vendor-transaction relationship. Then if user will create a transaction record using related entities area from within the vendor entity, the vendor and expense category both will get copied over the new record.
For a relationship mapping example please have a look over these links:
Save Time Entering Data into CRM by Mapping Fields between Records
TUTORIAL: Relationship Mappings
You could either setup mappings for Vendor and Expense, and create Transaction records only starting from Vendor records, or create a synchronous workflow to be run after Expense is created to copy over the field (in this second scenario, it doesn't matter how Transaction records are created, they'll always be populated, as long as you pick a Vendor).
You could also make your Expense in Transaction a Calculated field and make it always be the same as Vendor's value but it might not work for you (you aren't able to pick the value manually if you want it to be something else)

MS CRM 4 - Custom entity with "regardingobjectid" functionality

I've made a custom entity that will work as an data modification audit (any entity modified will trigger creating an instance of this entity). So far I have the plugin working fine (tracking old and new versions of properties changed).
I'd like to also keep track of what entity this is related to. At first I added a N:1 from DataHistory to Task (eg.) and I can indeed link back to the original task (via a "new_tasksid" attribute I added to DataHistory).
The problem is every entity I want to log will need a separate attribute id (and an additional entry in the form!)
Looking at how phone, task, etc utilize a "regardingobjectid", this is what I should do. Unfortunately, when I try to add a "dataobjectid" and map it to eg Task and PhoneCall, it complains (on the second save), that the reference needs to be unique. How does the CRM get around this and can I emulate it?
You could create your generic "dataobjectid" field, but make it a text field and store the guid of the object there. You would lose the native grids for looking at the audit records, and you wouldn't be able to join these entities through advanced find, fetch or query expressions, but if that's not important, then you can whip up an ASPX page that displays the audit logs for that record in whatever format you choose and avoid making new relationships for every entity you want to audit.
CRM has a special lookup type that can lookup to many entity types. That functionality isn't available to us customizers, unfortunately. Your best bet is to add each relationship that could be regarding and hide the lookups that aren't in use for this particular entity.

Resources