[D365 CE Online] Debug Async Plug-in using “Persist to Entity” profiler option
Dynamics 365 Installation – Part 6 – Installing CRM Back End Server Installation
Tips&Tricks: Automatic Cost Adjustment
Development Tools? You don't always need a UI!
One of the most underused tools in Dynamics and CDS development teams the myriad of those available is the Microsoft.Xrm.Data.PowerShell library by the ever helpful Sean McNellis. If you have to perform repetitive tasks then there is nothing easier but with the unfamiliar nature of PowerShell for those of us that write C# or JavaScript on a daily basis, it's often avoided.
This post is a call to action - consider it as an option for the following reasons:
- You can quickly convert Excel spreadsheets into a PowerShell script to perform repetitive tasks such as adding roles to users or entities to solutions.
- Easily create reusable scripts that are parameterized without the complexity of a user interface.
- Easily automate build tasks and run them over and over again with no chance of human error
- Creating scripts to give to other people to run as their user account when you don't have access to the target environment
Recently I needed to add a load of entities to a solution which can be quite cumbersome using the classic solution UI and the PowerApps solution manager doesn't allow you to add entities without their sub-components yet - PowerShell to the rescue.
# Shows how to add entities to a solution Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope CurrentUser Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser Import-Module Microsoft.Xrm.Data.Powershell $conn = Connect-CrmOnlineDiscovery -InteractiveMode Function Add-SolutionComponent { param ( [string]$solutionuniquename, [Int32]$componenttype, [Guid]$componentid ) # See https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327422(v%3Dcrm.8) $addrequest = new-object Microsoft.Crm.Sdk.Messages.AddSolutionComponentRequest $addrequest.AddRequiredComponents = 0 $addrequest.ComponentType = $componenttype #1=Entity $addrequest.DoNotIncludeSubcomponents = 1 $addrequest.ComponentId = $componentid $addrequest.SolutionUniqueName = $solutionuniquename $response= $conn.ExecuteCrmOrganizationRequest($addrequest) } Function Add-EntitiesToSolution { param ( [string]$solutionuniquename, [string[]]$addentities ) Write-Host "Checking that solution exists '$solutionuniquename'" $solution = Get-CrmRecords -conn $conn -EntityLogicalName solution -FilterAttribute uniquename -FilterOperator eq -FilterValue $solutionuniquename -Fields solutionid $solutionid = $solution.CrmRecords[0].solutionid Write-Host "Querying metdata to get entity id" $entities = Get-CrmEntityAllMetadata -conn $conn -EntityFilters Entity -OnlyPublished $false # Filter by the entities to add foreach($entity in $entities | ? {$_.LogicalName -in $addentities}) { $logicalName = $entity.LogicalName $count = (Get-CrmRecordsCount -conn $conn -EntityLogicalName $logicalName -WarningAction SilentlyContinue) Write-Host "Adding $logicalName" Add-SolutionComponent -solutionuniquename $solutionuniquename -componenttype 1 -componentid $entity.MetadataId } } # Add lead, account and contact to the solution TestSolution Add-EntitiesToSolution -solutionuniquename "TestSolution" -addentities "lead","account","contact"
So there you have it! I've picked this scenario because it shows some common things you'll need to use regularly:
- Querying for records
Get-CrmRecords
- Executing SDK Messages
ExecuteCrmOrganizationRequest
- Iterating and filtering collections
foreach($entity in $entities | ? {$_.LogicalName -in $addentities})
So there you have it. Hopefully, you'll consider using PowerShell if you've not already!
You can find lots more samples on Sean's git hub samples repo.
How to connect to your Business Central Docker sandbox database with SQL Server Management Studio or Visual Studio Code
2nd Holiday Calendar Post
MB2-719 Certification: Dynamics 365 for Marketing, Introduction
Object Table – Locked Missing
How Will You Measure Success? (Part 2) The Metrics You Need
CrmRecordId and IsNew Output in CRM/CDS Destination Component
Formating Web API query for getting VoC Survey questions
The trick, as the payment model is per run, is to trigger it per Survey Response, and not Question Response. Hence the logic has to loop through all the question responses.
The way you create a filter in Flow for the query is to use Odata filters. However, I found that these were a casing nightmare, which those of you who have worked with more, probably also have noticed.
After troubleshooting a lot with different queries in the browser I finally found that the following actually worked. Note that you will have t change the guid to your own.
https://dev-dtn.api.crm4.dynamics.com/api/data/v9.1/msdyn_questionresponses?$select=msdyn_name,msdyn_SurveyResponseId&$filter=msdyn_SurveyResponseId/msdyn_surveyresponseid%20eq%20460279E7-2AF2-E811-A97F-000D3AB0C08C
The tricky part, as you can see, is that the first part of the lookup attribute, is defined in camel-case and the one in the related entity (Survey Response) in lower case.
The part you need in the Flow is the last part, but it is useful to test it directly in the browser to make sure you get the syntax correct.
Its the filter part of the query that you are to enter into the "Filter query" field, and make sure to make it dynamic. :) |
And this is how it looks in Dynamics 365 CE if you check out the fields. I like to look at them in the list view as I can see the schema name there, which isn't visible in the Form.
msdyn_SurveyResponseId Lookup from the Question Response Entity. As you can see it seems to be using the Schema name above. |
Hence based on the above, the supposition would be that the syntax is <Schemaname of the lookup>/<name of field in target entity>
I then did a query to business Unit and I was very surprised to find that it was rather inconsistent and looked like this:
https://dev-dtn.api.crm4.dynamics.com/api/data/v9.1/businessunits?$select=cntso_organizationbaseurl&$filter=parentbusinessunitid/businessunitid%20eq%20null
with just the query that would be
parentbusinessunitid/businessunitid eq null
Let's have a look at the fields in Dynamics:
The Parent Business Unit Lookup in Business Unit (Self Referential). Note that the Schema name is Pascal Case. |
key field, businessunitid in Business Unit |
And as you can see, if we were to follow the syntax set by the example above, this should be:
ParentBusinessUnitId/businessunitid
However, that didn't seem to work, and as a pragmatist, I have to conclude, somewhat sad, that this doesn't seem to be very consistent.
My recommendation is hence when working with this:
- Do not take any casing for granted
- <Schemaname of the lookup>/<name of field in target entity> is probably correct for most custom fields/entities.
- Many older entities and fields, like the businessunit shown above, has been there since CRM 1.0 or at least 3.0, if I remember correctly and hence the syntax might be different.
- Test your queries directly in the browser like I have shown above.
Good luck with your Flows.
And if you know Swedish, make sure you check out my colleague Martin Burmans article on Flow as well. Not sure how well it turns out in translation. https://www.crmkonsulterna.se/flow-i-medvind/
Gustaf Westerlund
MVP, Founder and Principal Consultant at CRM-konsulterna AB
www.crmkonsulterna.se
Replace Dialogs with Microsoft Flow
We all know or should know that Microsoft Dynamics 365 Dialogs have been deprecated. When introduced Dialogs allowed a Functional Consultant to create an interactive step-by-step data entry form. The replacement options now are either business process flows or Canvas Apps. Both of which are reasonable alternatives and the latter, embedding PowerApps presents some really exciting possibilities.
But what if you need something a little simpler and perhaps utilize something you have already built? If it is a Microsoft Flow I will show you the simple steps you can do to embed an Button Flow into the Dynamics 365 Customer Engagement application.
Let’s consider this business scenario.
You have a busy Sales Exec at your company that refuses to login into the Dynamics 365 application to see what is going on with Opportunities. This person keeps emailing or calling you to have you email them a list of all the new Opportunities. I am going to keep this scenario simplified in the blog post but you can take what you learn and make it more complex.
Let’s imagine that previously you created a Flow Button and installed the Flow app on the Sales Exec’s phone. All the Exec had to do was to open the Flow App, tap on the Button and it would send directly to the exec a list of all the new Opportunities created in the last 24 hours.
But now the Exec calls you and keeps changing the time frame. And also refuses to even use the Flow App.
So your idea is to take the original Flow Button and modify it so you can vary the time for new Opportunities and it is business logic you can kick off from within the Dynamics 365 Web Client were you, as the Sales manager, live all the time.
Step 1– Take the existing Flow Button and make a copy.
Step 2– Edit the Flow to delete the Manually Trigger a Flow Button element.
Step 3 – Insert the Common Data Service When a Record is Selected Trigger. This will cause the Flow to be available from the Toolbar Flyout from the Opportunity Grid View. Add an Output field to prompt you to enter the number of days you want the report to cover for new Opportunities.
Step 4 and a little more– here we need to initialize a variable, then set the variable with the output from the prompted question so we can use it in the Get Past Time Step.
Step 5– There is nothing else we need to do except modify the To: field in the Send an Email Action. For the purposes of the blog post I am retrieving my own email address as the executor of the Flow. You could either hard code your bosses email address here (I don’t have a boss, I own the company. ) or you could add to the prompt for the recipients email address and use it in this later step.
Step 6– Now go to the Opportunity Grid View, select one row (this is required, doesn’t matter which record) and then click as shown in the image below.
Step 7– After clicking on the Copy of – Receive… link, the Flow ‘Dialog’ Window will open up. Now respond the prompt and enter the number of days.
Step 8– With a little bit of luck will see a screen as follows with all green check marks meaning your Flow has run successfully. The email to your Exec will have been sent out.
There is much more you can do with the process. I just wanted to show you the basic framework to get you started. Happy Flowing!
The post Replace Dialogs with Microsoft Flow appeared first on CRM Innovation - Microsoft Dynamics 365 Consulting and Marketing Solutions.
Tips&Tricks: Invoice Rounding Feature on Item Cost
[Tutorial] Automating Release to Warehouse process through Wave Template configuration
Google Chrome Browser Profiles
Seek and you shall (most likely) find: Search timeout
Access Reports in Dynamics 365 Unified User Interface
MSDYN365BC - Why Customer and Developer Should Choose AL over C/AL?
I have received so many comments and email about how to code with New changes.
There are so many confusion and wrong assumptions with these changes that Microsoft is bringing in the product.
Old Way - #MSDNAV <==> New Way - #MSDYN365BC