Wednesday, 20 February 2019

Regression Suite Automation Tool - Create unique values

The RSAT doesn't have any roll back feature. So, it can be frustrating updating the excel file with
unique records.


Well not to worry - RSAT supports Excel formulas. The user guide suggests using RandBetween(a,b) Excel function.
However, that isn't really reliable and you are hoping you don't get the same random number.

I have been using date formula. The below concatenates the datetime to the string.
=CONCATENATE("SS",TEXT(NOW(),"yymmddhhmmss"))


If you want to get started with RSAT.
Download the tool and the user guide from here.
https://www.microsoft.com/en-us/download/details.aspx?id=57357

You can also watch a short video that walks you through how to use it.

Wednesday, 23 January 2019

Azure DevOps Release Pipeline–Walkthrough


It is a great start to 2019. Joris from Microsoft has welcomed the year with the release of the Azure DevOps Release Pipeline task on the marketplace.
I thought I would do a walkthrough for those that haven’t had a chance to play with it yet.

New release pipeline
In Azure DevOps, click on the New release pipeline.

You will get an option to select from a template. Just select “Empty Job”.
In the first stage, make sure the Agent job is using “Hosted VS 2017”.


In the Agent job click on the + icon to add a task. Select the LCS Asset Upload task.
If you don’t see, then you have not installed it. Just select the “Dynamics 365 Unified Operations Tools”
link at the bottom. Otherwise, install from here

Stages
Now that you have the first task added. Fill in the details. You will have to add a
new connection to LCS. I need to investigate the tags to give it a better name and description.

When you click on the new LCS connection, you will get this dialog. Most of it is defaulted for you. Enter the username and password.
Client ID (Application ID) can be created in Azure Portal.
You need permissions to “Dynamics Lifecycle services”. Make sure it is a
Native application type. Hopefully it looks like the screenshot below.
Don’t forget to click on “Grant permissions”.
Artifact
Next, we go back to the main Pipeline screen and select our artifact.
Click on the Add an artifact tile. Select build and fill in the details.
What we want to do in this scenario is release the latest build.

Trigger
To set up a trigger to occur on a build. Click on the lightning icon. You can enter
filters to ensure only your release branch gets uploaded to LCS.
Run
You can run it manually to test it out. Click on the Create a release.
A successful run should look like this.
LCS
It is pretty satisfying to see the result on LCS.

Friday, 18 January 2019

Data Entity stuck “In Process”

There are a few reasons a scheduled data job may not execute. I made a silly mistake and it seemed as though the jobs where stuck on “In process”.
Things I checked:
1. Check the job isn’t disabled. See screenshot below. There is a toggle.
2. Check your recurring batch job is scheduled
3. Check you haven’t made any mistakes when enqueuing the entity. (I made a typo here)
I made the mistake of copying the URL and not changing the entity name. See the highlighted part in the url.
https://myenviornment.cloudax.dynamics.com/api/connector/enqueue/123456789-5506-4314-874D-3CF51A7AE15A?entity=General%20journal&company=usmf






















Below is a screenshot of the record info. You can see the Entity field contains the string I passed via the enqueue URL.



























Sounds pretty simple but hopefully helps someone out there.

Wednesday, 14 November 2018

Recurring import General Journal file using Microsoft Flow #MicrosoftFlow #MSDyn365FO

Microsoft Flow is a simple and cost effective way of integrating. In this post I will walk through how to use Flow for recurring file integration. The most common scenario I can think of is the general journal import.

First, I would recommend reading Microsoft article on recurring integration.

https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/data-entities/recurring-integrations

Solution below shows you how to use Microsoft Flow to read from OneDrive for Business and import to FinOps. The exact same thing can be done using Logic Apps for a more enterprise managed solution.

Lets start by setting up our folder structure to drop our general journal files in. Create four folders like so:

  • inbound – drop the files here to be processed
  • processing – Flow will move the file here from the inbound folder while executing
  • success – Flow will move it here when the file has successfully been imported and processed
  • error – Flow will move it here if the file fails to process for any reason

Now in Microsoft Flow designer, place a “When a file is created” and select the inbound folder.

image

In the next step, I used “Initialize variables” to be able to quickly change settings later in the flow. Otherwise, it can get messy to maintain and move around.

You might ask why I used an Object type rather than a String. In a string, I can set a single variable only. However, with the object I used a json string which allows me to set up multiple variables. (Let me know if this can be in a better way)

image

I parsed the json string. You can do this easily by copying the json string from above. Then click “Use sample payload to generate schema” to paste it in. It will generate the schema for you.

image

Next two steps is moving the file from inbound folder to processing folder. However OneDrive for Business doesn't have a Move action. I had to use a Create and Delete action as two steps. If you are using OneDrive for personal you will see a Move file action.

Once its moved, I use “Get file content” action to read the file.

image

Next, I used an HTTP POST action to send to the enqueue the file. I use the variables that were initialized earlier.

In the header I am setting the external identifier as the name of the file. This is done so in FinOps we can identify the job by the name.

image

This is what the result looks like in FinOps.

image

We are done sending the file to FinOps. The next steps are doing some cleaning of the file by moving to the success or error folder. Or you can email someone when a file is process or it errors out. You can get fancy.


However, I will show an example what you can do. Below I check every minute for 60 minutes if the job has been processed in FinOps. You can change the interval.

I added a “Do until” action. This is a loop that executes at an interval for a time limit.

image

The advanced query from the above is pasted below for your convenience. Its just doing an “or” condition. It checks if it is in any of these states.

@or(
      equals(body('HTTP_2')?['DataJobStatus']?['DataJobState'], 'Processed'),
      equals(body('HTTP_2')?['DataJobStatus']?['DataJobState'], 'ProcessedWithErrors'),
      equals(body('HTTP_2')?['DataJobStatus']?['DataJobState'], 'PostProcessingError'),
      equals(body('HTTP_2')?['DataJobStatus']?['DataJobState'], 'PreProcessingError')
    )

Initially it gets Queued, In Process and will go to Processed if it is successful.

All the statuses are listed here:

https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/data-entities/recurring-integrations

Next, I added a Condition to check the job status. If it is Processed, then I know it is successful. I can then move the file to the success folder. Otherwise, to the error folder.

image

I will stop here as the next few stops are pretty much a repeat of moving a file in OneDrive.

Why don’t you take it to the next level and check out Ludwig’s blog post on automating the posting of the general journal.

https://dynamicsax-fico.com/2016/08/17/automatic-posting-of-journals/

Tuesday, 30 October 2018

Debug Modern POS using .NET Reflector

Respect to all those POS developers. It really requires some dedication and focus to be a POS developer. This is an example of something I would have not figured out without my colleagues.


We were working on a development project and we struggled to make sense out of the error.

The error we got was complaining about the a method to validate the Unit of measure and Quantity. I was sure the object was not null and I had passed the right thing to it. Unit of measure and quantity fields were populated correctly. The modification was overriding the price.

System.NullReferenceException was unhandled by user code
   HResult=-2147467261
   Message=Object reference not set to an instance of an object.
   Source=Microsoft.Dynamics.Commerce.Runtime.Workflow
   StackTrace:
        at Microsoft.Dynamics.Commerce.Runtime.Workflow.CartWorkflowHelper.ValidateCartLineUnitOfMeasureAndQuantity(RequestContext context, Cart newCart, SalesTransaction salesTransaction, Dictionary`2 salesLineByLineId, CartLineValidationResults cartLineValidationResults)
        at Microsoft.Dynamics.Commerce.Runtime.Workflow.CartWorkflowHelper.ValidateUpdateCartRequest(RequestContext context, SalesTransaction salesTransaction, SalesTransaction returnedSalesTransaction, Cart newCart, Boolean isGiftCardOperation, IDictionary`2 productByRecordId)
        at Microsoft.Dynamics.Commerce.Runtime.Workflow.SaveCartRequestHandler.Process(SaveCartRequest request)
        at Microsoft.Dynamics.Commerce.Runtime.SingleRequestHandler`2.Execute(Request request)
        at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.Execute[TResponse](Request request, RequestContext context, IRequestHandler handler, Boolean skipRequestTriggers)
        at ECL.Commerce.Runtime.Donation.TriggerHandlers.SaveCartRequestHandler.Process(SaveCartRequest request)
        at Microsoft.Dynamics.Commerce.Runtime.SingleRequestHandler`2.Execute(Request request)
        at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.Execute[TResponse](Request request, RequestContext context, IRequestHandler handler, Boolean skipRequestTriggers)
   InnerException

After many hours over the course a few days we struggled. A colleague suggested to use .NET reflector (this is where you need an experienced retail developer). Using this tool, I was able to make sense of the problem.


Below are the steps to use .NET reflector.

1. Download .NET reflector

https://www.red-gate.com/products/dotnet-development/reflector/

2. Install following wizard. You can use the trial for 14 days or just active it with your serial number

When you install – I would recommend both the desktop and the visual studio extension

image

3. Select the assembly to debug. There are a couple of ways you can do that.

Select using the .NET Reflector > Generate PDBs (this will pop up a dialog to select the assembly)

image

Alternatively, from your solution explorer. Select the dll that is referenced and click on Enable Debugging.
image

4. This will launch the object browser.

Navigate to the method that caused the error. Then right click, Go to Decompiled Definition

image

5. I put a breakpoint and run through the process.

What I found was that it code used the salesTransaction object rather than the cartLine to get the unit of measure. Causing a cryptic error about unit of measure/quantity. In other words, I needed to create the cart line and save it to commit it to the salesTransaction first. Then after that process is finished, I can then override the price. i.e. 2 steps rather than trying to it all in one process.

image

I hope I don’t get in trouble of advising people to use .NET reflector by blogging here. I just don’t see how else I would have figure this thing out.

Wednesday, 17 October 2018

Send file to temp blob storage in #MSDyn365FO

In this post I will talk about sending a file to a temporary blob storage. A little warning before I get into it.

This is using the Microsoft’s blob storage that is provisioned for us. I haven’t given it a lot of thought on how it would behave in production. Take it at your own risk.

Lets start by looking back on a couple of posts last month on printing a report to a byte array.

http://dynamicsnavax.blogspot.com/2018/09/print-report-as-byte-array-via-x-in.html

http://dynamicsnavax.blogspot.com/2018/09/alternate-way-to-print-report-as-byte.html

You can use those sample pieces of code to get a report as a stream and send it to the below code.

if (stream)
{
    str fileName = 'myfile';
    str contentType = 'application/pdf';
    str fileExtension = SRSPrintDestinationSettings::findFileNameType(SRSReportFileFormat::PDF, SRSImageFileFormat::BMP);

    FileUploadTemporaryStorageStrategy fileUploadStrategy = new FileUploadTemporaryStorageStrategy();
    FileUploadTemporaryStorageResult fileUploadResult = fileUploadStrategy.uploadFile(stream, fileName + fileExtension, contentType , fileExtension);

    if (fileUploadResult == null || !fileUploadResult.getUploadStatus())
    {
        warning("@ApplicationPlatform:FileUploadFailed");
    }
    else
    {
        downloadUrl = fileUploadResult.getDownloadUrl();
        if (downloadUrl == "")
        {
            throw Exception::Error;
        }
    }
}

A download URL will be generated for you. The URL is going to be public and with an expiration (15 minutes I believe).

Below is an error if you try to access it after the expiration period.

image

Monday, 15 October 2018

Find TableId using table browser #MSDyn365FO

I am usually doing this from the development environment. However, I was debugging a customer environment where I only had access to the front end. I had a table that only gave me the RefTableId. I needed to find out the table that record related to.

I used SysTableIdView from table browser. Here is the link.

http://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=usmf&mi=SysTableBrowser&TableName=SysTableIdView

image