How to autogenerate Primary Name field in custom Common Data Service Entity? - dynamics-crm

Primary Name field is by default "Required". How to fill this field by GUID or random number on save?

Codeless solution: You can mark that field as not a Business Required, so you will be unblocked. You can use a codeless UI workflow to populate the Primary Name field with some fixed text. This WF can be triggered on post-create.
Code solution: Plugin can be triggered on pre-create & custom C# code can be used to pre-populate some autonumber/text in this field.
Pro tip: Model driven app is nothing but classic Dynamics CRM, so while searching for solutions use that keyword :)

There is a GUID() function in PowerApps that generates a random GUID. By default, its result is a GUID type of data (text, value, date, etc.).
Primary Name is a text field. To coerce the result of the GUID function to be a text string, wrap Text() around it:
Text(GUID())
So in your Patch statement or in the Update property of the field for PrimaryName, you can use the expression above to put in a GUID as a string.

Related

Business rule: Add other field value to date?

I'm trying to programmatically set the Due Date field of a custom activity. I want take the value of another date-time field that the users enters and add the value from an integer field. But it seems that I can only select a static value to add using the business rules as shown here:
Is there a way to do it using business rules? Or do I have to use a Javascript instead?
You can use calculated field for these scenarios, but it is not a physical field to store. If you have to store the value, then Javascript or plugin or WF is better.
Business rules are limited in these situations.
This should be quite easy using PowerApps expression language; no need for PowerApps "Rules" (which are slated to be deprecated).
To your app:
Add a DatePicker control
Add a TextBox control
Add a Label control
Set the Label control's Text property to:
DateAdd(
DatePicker.Selected.Value,
Value(TextBox.Text),
Days
)
Bingo!

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

Upsert fields must be defined as unique External ID fields in Salesforce - Heroku Connect

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.

Change length of name fields

We are using Dynamics CRM 2016 on-premise. When you create a custom entity, you get a default "name" field which is a string with 100 characters. You can change that datatype during entity creation but we didn't do that.
Now we learned that 100 chars are not enough in our usecase, we would need 120 or 150.
The solution designer allows changing the string length but when we save the changes we get a generic database error.
Question: Is there a known workaround to change the string length of the main field?
Obviously, it is possible to create a new entity and copy the data from the old to the new entity. Since we have many views, forms and references between entities, this is not really feasible.
This is not possible using any conventional solutions (i.e. through the UI) due to constraints in the Database. The default name field is the primary key of the table. I encourage you to remake the entity and migrate existing data to the new entity.
If this is really not feasible then you can try to change the length of the column directly in the SQL DB, but that is unsupported so it might break the environment. If you want to try this be sure that you test this in an disposable environment.
I have never done it so I don't know the outcome but that is something that I would try.

MS CRM - getting the field that caused a form save

I have a MS CRM 4 form where when certain fields are changed, I need those fields to be written to an excel sheet.
So, I edited the form field onchange event to call crmform.save() which triggers a plugin to run that writes the field value to a named range (1 cell) of an excel sheet.
However, I don't know which field caused the save. Is there a way to get that information? (Not all fields on the form need to go to the excel sheet)
If I use this: DynamicEntity target = (DynamicEntity)Context.InputParameters[ParameterName.Target];
I can look at specific fields, but I have no way of knowing which ones changed.
Any suggestions?
It's my experience that only the changed fields will have value (in the DynamicEntity) when you update an entity. So let's say you have an entity with a FirstName and Lastname. If you only change the LastName and save. The LastName will have a value however FirstName with be null (unless you have som javascript code that forces the FirstName to be submitted).
If your plugin is triggered on the Pre-Event of the Update on your entity, you should be able to compare the IPluginExecutionContext.PreEntityImages to your DynamicEntity that you've fetched from the Target.
Or if your plugin is triggered on the Post-Event of the Update, you should be able to compare the IPluginExecutionContext.PreEntityImages with IPluginExecutionContext.PostEntityImages.
Looks like you are already going a different way, but another suggestion is to create a hidden field - "FieldThatChanged." In your field on-change javascript, set that field to the name of the field that changed, then access that in your plugin.
Yep, totally changed the way I approached this. I'm using jquery in an iframe to pass all the exact fields (name/value pairs) I want to a method of an ASPX file running in the ISV folder that takes the neccesary action. Thanks for the suggestions all!
I recommend using the Pre and Post Images as suggested by #Forgotten Semicolon. And in addition set the Filtering Attributes so the Plugin is triggered only on the change of the fields you care about.

Resources