Bind data to MS Dynamics CRM sub grid from external database - dynamics-crm

I am not able to set lookup fields on MSCRM sub grid from external database.
I tried with the retrieve multiple plugin as:
get the data from external database in datatable
EntityCollection entityCollection= (EntityCollection)context.OutputParameters["BusinessEntityCollection"];
Entity anyEntity= new Entity("entity");
anyEntity.Attributes["new_customerid"] = new EntityReference("contact", new Guid("B26EF3E7-BD68-E411-9447-00155D010B06"));
anyEntity.Attributes["new_address1"] ="value from datatable";
entityCollection.Entities.Add(anyEntity);
Except lookup type field I am able to bind all the fields to the sub grid from external database.

This is expected since you cannot "look up" to a record in a different database. CRM enforces foreign key constraints on lookup fields so that you can only set a lookup value to point to an entity that actually exists in that CRM system. You could however set the lookup to a value in CRM based on some value in the other database.

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 Lookup Data into Model Driven PowerApps Custom Entities

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

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.

Fetch value of a field from one entity to second entity based on the lookup field selected in second entity using Fetch XML

I am new to CRM. I have a requirement where I have an "account" entity and a "contact" entity. In contact form I have a lookup field for searching account name which is stored in account entity. When I select an organization through lookup, the contact number of that organization should be fetched and saved in another field in contact form. I need to do it with fetch XML.
Option 1: You can do a no-code solution by mapping fields between account & contact.
Option 2: If you don't want a physical copy of field value in both entity, use Quick view form of Account lookup to just display the fields in contact without storing redundant data.
Option 3: If you still want to store the value onchange of account, retrieve it & set it in contact field. This step by step guide will help you to build fetchxml & use it in JS. Your question doesn't say if you are stuck in query or any error.

Bind Sub-Grid before creating the record CRM

i want to bind the sub grid of entity before creating the entity record i tried to fetchXml when on entity form load but it didn't work
Subgrids are disabled before you create the record.
This because without the Id of the main record it's not possible to associate other records (with 1:N or N:N relationships)

Resources