Exporting and importing solution using PowerShell

 

 

Powershell scripts are used with data centres, clouds, virtual machines, servers and applications to perform a variety of administration tasks, and Dynamics 365 is not an exception. The following script can be used to export a solution from one environment and import into other. It works with managed, unmanaged, and patch solutions. Execution of script can be triggered manually or it can be put into release pipeline.

About Script

This script uses Microsoft.Xrm.Data.Powershell (it is a great module to work with Dynamics 365 implemented by Sean McNellis and Kenichiro Nakamura). The script will attempt to install the module in case it is missing. Don’t forget to update CRM credentials, URLs and solution name in code.


#Update name of solution in below line, instead of rte_V1 add name of solution
$solutionName =”rte_V1″
$env:TEMP
Set-StrictMode -Version latest
function InstallModule{
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
$moduleName = “Microsoft.Xrm.Data.Powershell”
$moduleVersion = “2.7.2”
if (!(Get-Module -ListAvailable -Name $moduleName )) {
Write-host “Module Not found, installing now”
$moduleVersion
Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force
}
else
{
Write-host “Module Found”
}
}
function GetCrmConn{
param(
[string]$user,
[string]$secpasswd,
[string]$crmUrl)
Write-Host “UserId: $user Password: $secpasswd CrmUrl: $crmUrl”
$secpasswd2 = ConvertTo-SecureString -String $secpasswd -AsPlainText -Force
write-host “Creating credentials”
$mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd2)
write-host “Credentials object created”
write-host “Establishing crm connection next”
$crm = Connect-CrmOnline -Credential $mycreds -ServerUrl $CrmUrl
write-host “Crm connection established”
return $crm
}
InstallModule
#Update Source CRM instance details below:
Write-Host “going to create first connection”
$Crm1 = GetCrmConn -user “user@crm1st.onmicrosoft.com” -secpasswd “P@ssword001122” -crmUrl “https://crm1st.crm6.dynamics.com”
Write-Host “first connection created”
Set-CrmConnectionTimeout -conn $Crm1 -TimeoutInSeconds 1000
#Update target CRM instance below:
Write-Host “going to create second connection”
$Crm2 = GetCrmConn -user “user@crm2nd.onmicrosoft.com” -secpasswd “P@ssword001122” -crmUrl “https://crm.crm6.dynamics.com”
Write-Host “second connection created”
Write-Host “Exporting Solution”
Export-CrmSolution -conn $Crm1 -SolutionName “$solutionName” -SolutionFilePath $env:TEMP -SolutionZipFileName “$solutionName.zip”
Set-CrmConnectionTimeout -conn $Crm2 -TimeoutInSeconds 1000
Write-host “Importing Solution”
Import-CrmSolution -conn $Crm2 -SolutionFilePath “$env:TEMP\$solutionName.zip”
Write-host “Solution Imported”

I hope this is helpful.

Enjoy your 365 day.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

Flow variables

FlowVariables

 

Today I was doing a Flow task and to complete it I used variable as a flag. It is very interesting Flow is a “No Code” approach but still many coding concepts are available in it. Having development experience or knowledge just open another door of creativity. The good thing is in Flow “No Code” means we don’t write code, rather we use code blocks as actions to do different things. We don’t have the flexibility of custom code but available code features are very useful.

For “variable” connector at the time the following six actions are available:

  • Initialize variable
  • Set variable
  • Increment variable
  • Decrements variable
  • Append to array variable
  • Append to string variable

Variables1

Variables2

Variables3

Here is a little description of these actions. Using “Initialize variable” we can declare a variable, specify its type and initial value which can be dynamic or hard coded. At the time supported types are Boolean, Integer, Float, String, Object, and Array. Set variable assigns a value to an existing variable. Increment  and decrement actions work with numeric types only. You can specify a number and variable value will be increased by that number.  Append (array and string) actions add new value at the end of existing variable values and are often used in iterations.

I hope this is helpful.

Enjoy your 365 day.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

Quick Tip: Fixing Plugin registration tool crash after login

Plugin registration tool (v.9) was working fine but I had to change the user account to deploy a plugin and tool started crashing. It was accepting my password, showing available CRM instances, and after I select the instance, without reporting any error it was crashing.

To fix I downloaded plugin registration tool again and also deleted files from:

C:\\AppData\Roaming\Microsoft\PluginRegistration

I hope this quick tip is helpful.

Enjoy your 365 day.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

Quick Tip: How to modify view FetchXML

We can easily create or modify a view in Dynamics 365, this basically generates and saves view FetchXML. It is a great feature but we don’t have control to modify FetchXML. The good news is it can be done without writing code. “View Designer” is another useful XrmToolBox plugin which allows editing of view FetchXML, save and publish it back. I hope this quick tip was helpful.

#MSDyn365 #MsDynCRM

Enjoy your day of 365 life.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

System Jobs monitoring using Flow

  MonitoringMain

System Jobs

AsyncOperation or System Job is an important Dynamcis 365 system entity. Usually we don’t create its records, rather they are created automatically. A record represents a single execution of an asynchronous resource. They include important details about asynchronous operation like name of resource, status (waiting for resources, waiting, in progress, pausing, cancelling, succeeded, failed and cancelled), time of execution and error details in case thing go wrong. We can view system jobs by navigating to  Settings > System Jobs.  There are 68 (or more) types of system jobs but as a CRM  user commonly we use the following asynchronous operations:

  • System Event (Asynchronous Plugin)
  • Workflow
  • Bulk Delete
  • Bulk Email
  • Import
  • Rollup Field

A few system related types are:

  • Index Management
  • Database Tuning
  • Collect Organization Storage Size
  • Calculate Organization Maximum Storage Size
  • Storage limit notification

For complete details of System Job types see “OperationType” attribute in “AsyncOperation” (System Job) entity.

Why we need to monitor System Jobs?

It is quite common to use asynchronous workflow, asynchronous plugin, rollup field, bulk delete or import features. Since they are asynchronous, most of the time we will not get a notification if they fail until we go and check status.

New To Flow ?

If you are new to Flow, in the following post I have discussed basics of Flow. Please go through it if you need more understanding of Flow basics:

https://crmtechie.com/2018/05/24/create-contact-from-received-email-using-flow/

About demo

We can navigate and see status when we need. It is useful but sort of manual. It will be good to have a piece of automation which may periodically inform power user or admin about failed jobs. In this demo I will use Flow to send a scheduled email (once a day in this demo but of course it can be configured as per requirement), listing the status of failed jobs. This approach can be used in different scenarios.

This solution works in the following 4 steps:

  1. At a scheduled time flow execution starts
  2. Filter, sort and read system job records from CRM
  3. Create HTML table from CRM records
  4. Finally send HTML table in an email 🙂

Let’s begin:

Step 1:

  • Sign in to https://flow.microsoft.com/ and click “My flows”
  • In next page click “Create from blank”
  • Click “Create from blank” again in next screen 🙂
  • Select or search “Schedule” from connectors

Monitoring1Monitoring2

Monitoring3

Monitoring4

  •  Click “Schedule – Recurrence” and later configure time zone and start time. I m using “1” as “Interval” and “Day” as “Frequency”

Monitoring5

  • From “Show advanced options”, select time zone and start time. I m using “(UTC + 10:00) Canberra, Melbourne, Sydney” as time zone and  “2018-06-08T10:15:00Z” as the start time.

Monitoring6

Step 2:

  • Click “+ Add New step” and then “Add an action”
  • Search “Dynamics” in the list of connectors and actions and select “Dynamics 365”
  • From actions select “Dynamics 365 – List records (Preview)

Monitoring7

Monitoring8

  • Click Menu ( ), and then sign in to your Dynamics 365 instance by pressing “+ Add new connection”
  • From “Show advanced options” do the following configurations:
    • Select your Organization Name
    • “System Jobs”  in “Entity Name” field
    • “statuscode eq 31” in Filter Query (for details see this)
    • “startedon desc, createdon desc” in “Order By” field

Monitoring9

Step 3:

  • Search and add new action of type “Data Operations – HTML table”
  • Click “From” field and select “value” from Dynamic content window

Monitoring10Monitoring11

  • Clicking “Show advanced options” to add the data columns
  • Enter heading, click Value part and select column from “List records” window
  • For better spacing between columns, add an empty column between every two columns and use a character or combination (| or . or : or ::) in header
  • I have used System Job Type, System Job Name, Status Reason Label and Created On columns for reporting

Monitoring12

Step 4:

  • Search send email and add Outlook or Gmail connector
  • From actions select send an email
  • From ( … ) menu sign in and  add connection to your mail box if you are not already connected

Monitoring13

  • Enter “To” email address and subject
  • Click in “Body” and from Dynamic content select “Output”

Monitoring14

  • From “Show advanced options” select “Yes” for “Is HTML” field
  • Save
  • Wait for execution as per time entered or from top right corner click “Test” for testing execution.

Monitoring15

Using Flow for monitoring can be used in interesting scenarios like scheduled monitoring, monitoring a particular async resource or type of resources and even to monitor progress while execution.

I hope you like this solution and Flow overall.

Enjoy your day of 365 life.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

Create contact from received Email using Flow

EmailToCRMUsingFlow2 copy

Last week in a meeting client explained requirement:

“.. we receive emails in a mail box, and we manually create contacts in CRM using sender name and address for further processing, we want to automate this.. .”

This task was going to extend existing system functionality but there was no existing code to reuse or modify and of course expectation was to deliver this soon. So it was a perfect case to use Microsoft Business Application Platform. In this post I will explain how easy it was to provide solution using Flow.

New to Flow ?

Flow is part of Business Application Platform and it is latest service from Microsoft to create automated workflow. It is intended for business and power users so most of the time tasks can be performed without writing a single line of code. Some of its cool features are:

  1. It integrates different systems and applications
  2. Create workflow and automation tasks
  3. Transfer data between systems
  4. Can be used easily with a bunch of other Microsoft technologies

To get started first step is to sign up at flow.microsoft.com. Currently there is a basic “Flow Free” plan which is free, for more details about pricing see this.

How Flow Works ?

There are three basic components in Flow which are connector, trigger and action.

Connector is used to connect to source and target system. A few examples of connectors are Dynamics 365, OneDrive, Gmail, Twitter, Excel, Azure Storage, Oracle, DB2, RSS, Eventbrite or Youtube. At the time almost 227 connectors are available and hopefully this number will increase.

A trigger is an event that occurs inside the connector. For example with SharePoint a few triggers are:

  • File creation
  • Deletion of a file
  • File modification

Similarly a trigger with Gmail is when a new email arrives. A connector can have multiple triggers and in a flow usually we chose a trigger which start execution of flow.

After selecting trigger normally next step will be to chose target system or service (again using connector). Similar to triggers with source connector, a target connector may have multiple associated actions to chose from. For example Office 365 Outlook has:

  • Create Contact
  • Send Email
  • Create Event

By choosing an action we tell what should happen to target system or server. Good thing is we can chose multiple actions which will be performed one by one. For example we can create a flow which on receiving an email will send a sms, create a file in Sharepoint and also create record in Dynamics 365.

Solution

  • Sign in to https://flow.microsoft.com/ and click “See all ” link
  • Search and select Gmail
  • Click “When a new email arrives”

ETOC1

ETOC2

CCFEF3

  • Click menu and sign in using your Gmail account using “+ Add new connection”

CCFEF4

  • Click “add an action”
  • Type Dynamics and then click “Dynamics 365 – Create a new record”

CCFEF5

  • Click menu and then from “+ Add new connection” sign in to Dynamics 365 account
  • Select your Dynamics 365 organization name in “Organization Name” field
  • Select ‘Contact’ as entity from “Entity Name” field
  • After selecting entity name more fields will be loaded in “Create a new record” form

CCFEF7

CCFEF8

CCFEF8.1.PNG

  • In form click “Last Name” and then from dynamic content list select “Sender’s Name”
  • Similarly select “Email” in create a new record form and then from dynamic content “From” email address
  • Press Save button to save the Flow and that is all !

CCFEF9

CCFEF10

CCFEF11

  • Send email to linked account and after 3-4 second verify new contact created in Dynamics 365 from email received.
  • Click “My flows” link and then click flow listed to verify its execution was successful

CCFEF12

CCFEF13

Note:

This demo was created using Gmail, but for Outlook, “Outlook.com” and “Office 365 Outlook” two connectors are available. One catch though is at the time they do not offer senders name as dynamic content. A solution can be to redirect Outlook emails to a Gmail box and configure Gmail to create a contact in Dynamics 365.

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal

Can’t connect when clock wrong

Probably title of this post summaries it well, but there is some detail worth explanation. I was developing an Azure Function app which was basically integrating data between CRM and another system. The major functionality of this application was complete and tested. Two weeks back when I came back from leave I found my application which was working fine before can’t connect to CRM. I was using Microsoft.Xrm.Tooling assembly with the following code but now it started returning null:

public static IOrganizationService GetOrganizationService(ref TraceWriter log)
{
IOrganizationService _orgService = null;
string connectionstring = ConfigurationManager.AppSettings["connectionstring"].ToString();
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionstring);
_orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
return _orgService;
}

CrmServiceClient has two very useful properties LastCRMError and LastCRMException which were showing this error message:

Unable to Login to Dynamics CRMOrganizationWebProxyClient is nullOrganizationServiceProxy is nullOrganizationServiceProxy is null

Tried looking for solutions and found the following suggestions:

  1. In connection string try Orgnaization unique name instead of friendly name
  2. May be assembly version is not compatible or code/ connection string should be written differently
  3. Use ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; before connection

but none of these worked in my case. I contacted Microsoft support and they confirmed there was no such update or roll out that might have caused this but the good thing is they were still willing to help 🙂

I tried different types of applications, environments and versions but no luck.

In last while testing the following code the error was a little more meaningful:


IServiceManagement orgServiceManagement = ServiceConfigurationFactory.CreateManagement(new Uri("https://myCrmInstance.crm5.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = “user@email.com”;
authCredentials.ClientCredentials.UserName.Password = “*********”;
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

OrganizationServiceProxy organizationProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
Entity contact = new Entity(“contact”);
contact.Attributes[“firstname”] = “Yawer”;
contact.Attributes[“lastname”] = “Iqbal”;
var contactId = organizationProxy.Create(contact);

 

“The security timestamp is invalid because its creation time (‘2018-04-01T12:30:45.790Z’) is in the future. Current time is ‘2018-04-01T12:24:29.185Z’ and allowed clock skew is ’00:05:00′.”

Getting hint about time I found time on my machine is 6 minutes behind. What caused this time change I still don’t know but since it was the difference of just 6 minutes I couldn’t notice this change. Corrected time and everything started working as it was. I thought to do a little experiment and moved clock 6 minutes ahead of current time and as per expectation error was different:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

and inner exception:

An error occurred when verifying security for the message.

Hope this sharing will save someone’s time.

Please feel free to share this post, leave comments or suggestions if there are any. If you like to remain informed about future posts please follow me.

Enjoy this beautiful day of your 365 life 🙂

#MSdyn365 #Dynamics365 #CRM #MsCRM

About Me 🙂

I m an IT consultant working in Melbourne Australia. I solve business problems using Microsoft technologies (Dynamics 365, Office 365, Azure, Flow, Power Apps, Power BI). I m involved in community activities and I blog at http://www.crmtechie.com/

I love to get connected with people working in IT, providing solutions or who just like Microsoft technologies. To get in touch please follow my blog, and connect through Linkedin, Twitter or Facebook

Blog: http://www.crmtechie.com/

Twitter: @YawerIqbal

Linkedin: YawerIqbal

Facebook: Yawer.Iqbal