Setting up notifications in Azure DevOps

Today one of the test guys in our project asked if it was possible to get a notification when code was pushed to a specific branch in DevOps… specifically the branch that meant that they needed to test something… this is what you do:

  1. Login into Azure Devops and go to User Setting – Notifications
  2. Click New Subscription, choose Code (TFVC) and Code is checked in
    Note: since this is a Dynamics 365 FO project we are using TFVC 
  3. Set the Path (or other criteria) you want to check for and click finish

    That is all…

Johan

Link
https://docs.microsoft.com/en-us/azure/devops/boards/queries/alerts-and-notifications?view=tfs-2017

Copy database from an Azure Sql Environment to a OneBox environment

Here is a checklist to copy a Dynamics 365 for Finance and operations database in from a tier-2 (or above) to a OneBox (Dev, Build or Test).

  1. Start by creating a new database as a copy of the original (since you are going to mess with it) by running this SQL query:
    CREATE DATABASE MyNewCopy AS COPY OF axdb_mySourceDatabaseToCopy

    Since this operation runs asynchronously in the background you will have to keep an eye on it before continuing:

    SELECT * FROM sys.dm_database_copies
  2. Prepare the database for export
    --Prepare a database in Azure SQL Database for export to SQL Server.
    --Disable change tracking on tables where it is enabled.
    declare
    @SQL varchar(1000)
    set quoted_identifier off
    declare changeTrackingCursor CURSOR for
    select 'ALTER TABLE ' + t.name + ' DISABLE CHANGE_TRACKING'
    from sys.change_tracking_tables c, sys.tables t
    where t.object_id = c.object_id
    OPEN changeTrackingCursor
    FETCH changeTrackingCursor into @SQL
    WHILE @@Fetch_Status = 0
    BEGIN
    exec(@SQL)
    FETCH changeTrackingCursor into @SQL
    END
    CLOSE changeTrackingCursor
    DEALLOCATE changeTrackingCursor
    
    --Disable change tracking on the database itself.
    ALTER DATABASE
    -- SET THE NAME OF YOUR DATABASE BELOW
    MyNewCopy
    set CHANGE_TRACKING = OFF
    --Remove the database level users from the database
    --these will be recreated after importing in SQL Server.
    declare
    @userSQL varchar(1000)
    set quoted_identifier off
    declare userCursor CURSOR for
    select 'DROP USER [' + name + ']'
    from sys.sysusers
    where issqlrole = 0 and hasdbaccess = 1 and name <> 'dbo'
    OPEN userCursor
    FETCH userCursor into @userSQL
    WHILE @@Fetch_Status = 0
    BEGIN
    exec(@userSQL)
    FETCH userCursor into @userSQL
    END
    CLOSE userCursor
    DEALLOCATE userCursor
    --Delete the SYSSQLRESOURCESTATSVIEW view as it has an Azure-specific definition in it.
    --We will run db synch later to recreate the correct view for SQL Server.
    if(1=(select 1 from sys.views where name = 'SYSSQLRESOURCESTATSVIEW'))
    DROP VIEW SYSSQLRESOURCESTATSVIEW
    --Next, set system parameters ready for being a SQL Server Database.
    update sysglobalconfiguration
    set value = 'SQLSERVER'
    where name = 'BACKENDDB'
    update sysglobalconfiguration
    set value = 0
    where name = 'TEMPTABLEINAXDB'
    --Clean up the batch server configuration, server sessions, and printers from the previous environment.
    TRUNCATE TABLE SYSSERVERCONFIG
    TRUNCATE TABLE SYSSERVERSESSIONS
    TRUNCATE TABLE SYSCORPNETPRINTERS
    --Remove records which could lead to accidentally sending an email externally.
    UPDATE SysEmailParameters
    SET SMTPRELAYSERVERNAME = ''
    GO
    UPDATE LogisticsElectronicAddress
    SET LOCATOR = ''
    WHERE Locator LIKE '%@%'
    GO
    TRUNCATE TABLE PrintMgmtSettings
    TRUNCATE TABLE PrintMgmtDocInstance
    --Set any waiting, executing, ready, or canceling batches to withhold.
    UPDATE BatchJob
    SET STATUS = 0
    WHERE STATUS IN (1,2,5,7)
    GO
    -- Clear encrypted hardware profile merchand properties
    update dbo.RETAILHARDWAREPROFILE set SECUREMERCHANTPROPERTIES = null where SECUREMERCHANTPROPERTIES is not null

    Remember to change the database namn on line 23

  3. Export the database
    cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin
    
    SqlPackage.exe /a:export /ssn:<server>.database.windows.net /sdn:MyNewCopy /tf:D:\Exportedbacpac\my.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false /sp:<SQLAdmin password> /su:sqladmin

    Note: I usually store the DB backup in an Azure Storage Blog since this is the easiest way to move file between environments. See here

  4. Import the backup in the target environment
    cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin
    
    SqlPackage.exe /a:import /sf:D:\Exportedbacpac\my.bacpac /tsn:localhost /tdn:<target database name> /p:CommandTimeout=1200

     

  5. When the database is imported you will need to prepare it for the new environment
    CREATE USER axdeployuser FROM LOGIN axdeployuser
    EXEC sp_addrolemember 'db_owner', 'axdeployuser'
    
    CREATE USER axdbadmin FROM LOGIN axdbadmin
    EXEC sp_addrolemember 'db_owner', 'axdbadmin'
    
    CREATE USER axmrruntimeuser FROM LOGIN axmrruntimeuser
    EXEC sp_addrolemember 'db_datareader', 'axmrruntimeuser'
    EXEC sp_addrolemember 'db_datawriter', 'axmrruntimeuser'
    
    CREATE USER axretaildatasyncuser FROM LOGIN axretaildatasyncuser
    EXEC sp_addrolemember 'DataSyncUsersRole', 'axretaildatasyncuser'
    
    CREATE USER axretailruntimeuser FROM LOGIN axretailruntimeuser
    EXEC sp_addrolemember 'UsersRole', 'axretailruntimeuser'
    EXEC sp_addrolemember 'ReportUsersRole', 'axretailruntimeuser'
    
    CREATE USER axdeployextuser FROM LOGIN axdeployextuser
    EXEC sp_addrolemember 'DeployExtensibilityRole', 'axdeployextuser'
    
    CREATE USER [NT AUTHORITY\NETWORK SERVICE] FROM LOGIN [NT AUTHORITY\NETWORK SERVICE]
    EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'
    
    UPDATE T1
    SET T1.storageproviderid = 0
        , T1.accessinformation = ''
        , T1.modifiedby = 'Admin'
        , T1.modifieddatetime = getdate()
    FROM docuvalue T1
    WHERE T1.storageproviderid = 1 --Azure storage
    
    ALTER DATABASE [<your AX database name>] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 6 DAYS, AUTO_CLEANUP = ON)
    GO
    DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking
    DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking_V2
    GO
    -- Begin Refresh Retail FullText Catalogs
    DECLARE @RFTXNAME NVARCHAR(MAX);
    DECLARE @RFTXSQL NVARCHAR(MAX);
    DECLARE retail_ftx CURSOR FOR
    SELECT OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id) fullname FROM SYS.FULLTEXT_INDEXES
    	WHERE FULLTEXT_CATALOG_ID = (SELECT TOP 1 FULLTEXT_CATALOG_ID FROM SYS.FULLTEXT_CATALOGS WHERE NAME = 'COMMERCEFULLTEXTCATALOG');
    OPEN retail_ftx;
    FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
    
    BEGIN TRY
    	WHILE @@FETCH_STATUS = 0  
    	BEGIN  
    		PRINT 'Refreshing Full Text Index ' + @RFTXNAME;
    		EXEC SP_FULLTEXT_TABLE @RFTXNAME, 'activate';
    		SET @RFTXSQL = 'ALTER FULLTEXT INDEX ON ' + @RFTXNAME + ' START FULL POPULATION';
    		EXEC SP_EXECUTESQL @RFTXSQL;
    		FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
    	END
    END TRY
    BEGIN CATCH
    	PRINT error_message()
    END CATCH
    
    CLOSE retail_ftx;  
    DEALLOCATE retail_ftx; 
    -- End Refresh Retail FullText Catalogs
  6. Switch to using the new database
  7. Stop these services
    World Wide Web Publishing Service
    Management Reporter 2012 Process Service
    Microsoft Dynamics 365 Unified Operations: Batch Management Service
  8. Rename the old database to AxDB_orig
  9. Rename the new database to AxDB
  10. Start these services
    World Wide Web Publishing Service
    Microsoft Dynamics 365 Unified Operations: Batch Management Service
    Management Reporter 2012 Process Service
  11. Synchronize the database from Visual Studio

Links
https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/database/copy-database-from-azure-sql-to-sql-server

 

 

Flow Friday – Adding flagged email to todo list

As you all know Microsoft Flow together with Outlook is able to add tasks when you flag an email. In my workflow I am unfortunately not using Microsoft ToDo… I have put all my tasks in Todoist but I think the feature is awesome… Microsoft flow to the rescue

  1. Lets start with creating the trigger which is flagged email in Outlook

  2. I want the tasks to end up in Todoists Inbox with prio 1… The reason for this is not that all email is important but it is important to triage the inbox in order to set the correct prio, labels and project.

    The expression is for getting todays date and looks like this:

    formatDateTime(utcNow(),’yyyy-MM-dd’)

Downloading Microsoft Ignite Sessions

This year I was not able to visit Microsoft Ignite 2019 but since there are more than 1900 session available for on demand viewing (and I would not have had time to watch the sessions I wanted anyway) that doesn’t really matter. I can always download them and watch them at home. If you hesitate on downloading all of them you can find your sessions/products/speakers of interest on the Ignite site 

To bulk download them you will need a script. I use this one but there are others out there that you can use. For this particular script to work you will need a tool called youtube-dl (which in turn requires Microsoft Visual C++ 2010 Redistributable Package (x86) ) and ffmpeg.exe. both tools will be downloaded by the script. In order to run scripts you download (this is done your own risk… only run scripts you trust) you will also need to set the execution policy in PowerShell

I do it for just the specific window that I use:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

To download the session I use these script lines:

.\Get-EventSession.ps1 -DownloadFolder 'D:\Microsoft Ignite 2019\' -Product "*Finance*" -Event Ignite -NoSlidedecks
.\Get-EventSession.ps1 -DownloadFolder 'D:\Microsoft Ignite 2019\' -Product "Power Platform" -Event Ignite -NoSlidedecks
.\Get-EventSession.ps1 -DownloadFolder 'D:\Microsoft Ignite 2019\' -Speaker "Jeffrey Snover" -Event Ignite -NoSlidedecks
.\Get-EventSession.ps1 -DownloadFolder 'D:\Microsoft Ignite 2019\' -Speaker "Mark Russinovich" -Event Ignite -NoSlidedecks
.\Get-EventSession.ps1 -DownloadFolder 'D:\Microsoft Ignite 2019\' -Product "Not Product Specific" -Event Ignite -NoSlidedecks

There are a lot of other filter possibilities in the script that you can explore… now, get downloading

Johan

Links:
https://gallery.technet.microsoft.com/Ignite-2016-Slidedeck-and-296df316#content

Flow Friday – Feeding news to MS Teams – Part 2

So… Apparently Flow is not Flow anymore 🙂 Flow is now called Power Automate but since the actual flows still are called flows I will keep the name Flow Friday…

Last week we startad posting news to Microsoft Teams… today we are expanding that concept… Same basic flow with a nice look and more news sources

Since we are not able to add multiple trigger to a Flow (yet?? *hoping*) and I am too lazy to build multiple flows… that would be cheating.

The multiple news sources requires a workaround using an external service called RSSUnify (there are other services that you can use). Go to RSSUnify and add all your feeds.

Then you copy the resulting RSS URL from RSSUnify and add it to Microsoft Flow

In order to refine the flow even more I want to make the Teams posting a little nicer. To do that I use the action “Post your own adaptive card as the flow bot to a channel (Preview)”. To design the look of the card you can either write your own JSON design or you can use this tool. I created a minimal card and the post information.

The card posting action has issues handling HTML which means that I will have to convert the summary into Plain Text. In order to fix this I add an action called Html to Text and then add the result to the adaptive card.

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
        {
            "type": "TextBlock",
            "text": "[@{triggerBody()?['title']}](@{triggerBody()?['primaryLink']})",
            "weight": "Bolder",
            "size": "Medium"
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "spacing": "None",
                            "text": "@{body('Html_to_text')}",
                            "isSubtle": true,
                            "wrap": true
                        }
                    ]
                }
            ]
        },
        {
            "type": "TextBlock",
            "text": "",
            "wrap": true
        }
    ]
}

The post looks like this:

That is it for this week

Links:
https://adaptivecards.io/
https://rssunify.com/

Themes in Chromium Edge

I have started using Microsoft Edge (the Chromium version) and I really like it… Since I am coming from Google Chrome it is not that different except for two main things. The first one is that Microsoft has their own extension store which has much less extensions (the most important ones are there) and you can also use the Google Chrome Store although you will manually click on a link to use it. The second difference is that Microsoft has blocked Apps and Themes from the Google Store which would not have been a big deal for me if it wasn’t for the fact that I use themes to differentiate between multiple browser windows using different user profiles. This is the best way I have found to use multiple Azure accounts at the same time without having to sign out and in all the time.

There is how ever a work around.

  1. Install the extension Get CRX which gives you the option to download the file for the extension.
  2. Find the theme you want in the Google Chrome Store
  3. Right-click the extension page and select Get CRX of this extension
  4. When the file is done downloading open the page edge://extensions in Microsoft Edge
  5. Drag and drop the file you downloaded into the Edge tab you opened in 4
  6. In order to install the them you will have to approve the install security warning

    Note: this is absolutely not the recommended way of installing an extension/theme, this is an ugly hack (a means to an end). If you are not sure please do not do this.

  7. Click add theme to add the theme

 

That is it…

Links:
https://chrome.google.com/webstore/detail/get-crx/dijpllakibenlejkbajahncialkbdkjc

How to create a sprint

This is mostly a checklist for me to remember how to add new Sprints (Iteration Paths) in Azure DevOps… I tend to forget since it is not done very often

  1. Go to Project Settings in Azure DevOps
  2. In Project Confiruration choose the parent Iteration Path and click New Child
  3. Add Name, Start date and End Date and click Save and Close
  4. To mage the Sprint visible you need to add is to a team (otherwise noone will see it). To do this go to Team Configuration, choose Iterations and click Select Iterations.
  5. Choose the new sprint and click Save and Close

That is it for today… have a nice Monday

Johan

Links:
https://docs.microsoft.com/en-us/azure/devops/organizations/settings/set-iteration-paths-sprints?view=azure-devops&tabs=browser
https://docs.microsoft.com/en-us/azure/devops/organizations/settings/set-area-paths?view=azure-devops&tabs=browser#guidance

Flow Friday – Feeding news to MS Teams

The other day I asked my colleagues to provide me with good real world problems that I could help them solve in Power Platform. The first challenge was “Could you add news feeds in Microsoft Teams”. No problems 🙂

Create a new Flow and start with the RSS component and add the adress to the RSS feed.

Add the Microsoft Teams component called Post a Message V3 (Preview), select your Teams Tenant and the channel where you want to post the news posts.

Create the message and add Feed Title, Primary Feed Link and Feed Summary. In my case I want the title to be clickable and go to the original post in a new window. This required a small trick. Add a link from the UI using dummy text and link and the go to the code view ( </> ). Here you can replace both text and link with Feed Title and Primary Feed Link

Now we wait… for a post

That is it for today…

Keep Flowing

Flow Friday: Notifying your a bit extra

Today’s Flow Friday is a fairly simple one. Since I some times is a bit preoccupied and not able to keep up with my email and I also try to minimize notifications on my phone it would be very nice to have an extra notification when I receive an email where someone specifically mentions my name.  With flow this is simple…

In this flow I might be going a bit overboard 🙂

  1. When an email where I am mentioned arrives I the flow is triggered.
  2. The email is flagged
  3. A task is created in Todoist saying that I need to handle flagged emails
  4. … end a notification is sent to my phone.

This means that I will only get notified when I am mentioned 🙂

Happy Weekend

Issues compiling label files

Yesterday evening (why does it always have to be evenings 😉 ) I was going to do a deploy of code to our staging environment. I started the build in Azure Devops and it failed:

C:\DynamicsSDK\Metadata\Microsoft.Dynamics.AX.Application.Build.targets(78,5): error MSB6006: “LabelC.exe” exited with code -1. [C:\DynamicsSDK\Metadata\BuildMetadata.proj]

OK… SO LabelC.exe atleast gives me some hints and since the deployconsisted of changes to Label Files this was not too strange. I downloaded the log file and found this information:

outlog=C:\DynamicsSDK\VSOAgent\_work\10\Logs\ModelName\Dynamics.AX.ModelName.labelc.log

So I looked in the log file on the build server and found the following:

The error was duplicate lines in two label files

Remove them by editing the file in Azure DevOps and check in the file. Restart the build and it worked… Way