Skip to content

Instantly share code, notes, and snippets.

@rezanid
rezanid / postman-visualize-plugintracelogs.js
Created April 7, 2024 12:12
Visualize Postman results for Power Platform's Plugin Trace Logs
const moment = require('moment');
var template = `
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
<style>
.table-responsive-custom {
display: block;
width: 100%;
overflow-x: auto;
@rezanid
rezanid / Postman-PreRequest-Authentication.js
Last active April 5, 2024 05:37
Postman Pre-Request script to authenticate and refresh authentication token using OAuth2 device flow
// Environment Variables:
// url: <your-resource> example: https://myfancyapp.crm4.dynamics.com
// clientid: <user-clientid-from-appreg> example: 1950a258-227b-4e31-a9cf-717495945fc2
// To know how to use this script, please read the following blog post:
// https://bycode.dev/2024/04/04/automatically-authenticate-in-postman-with-pre-request-scripts/
const utils = {
auth: {
message: "",
async refreshAuth() {
@rezanid
rezanid / Directory.Build.props
Created September 18, 2023 16:56
Upgrade C# language version for .NET Framework 4.x
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<LangVersion>11</LangVersion>
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
@rezanid
rezanid / Add-Path.ps1
Last active August 28, 2023 14:38
Adding PATH to Windows permanently (and safely) the right way using PowerShell
function Add-Path {
param(
[Parameter(Mandatory, Position=0)]
[string] $LiteralPath,
[ValidateSet('User', 'CurrentUser', 'Machine', 'LocalMachine')]
[string] $Scope
)
Set-StrictMode -Version 1; $ErrorActionPreference = 'Stop'
@rezanid
rezanid / JsonConverters.cs
Created May 7, 2023 19:05
Json Converters to facilitate unit testing for Power Platform's Custom APIs
using Microsoft.Xrm.Sdk;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace MyFancyPlugins.Tests.JsonConverters;
/// <summary>
/// Allows serialization / deserialization of <see cref="Microsoft.Xrm.Sdk.EntityCollection". This type is
/// intended for unit-testing only./>
@rezanid
rezanid / FetchUtil.cs
Created February 22, 2022 15:33
Power Platform (Dynamics) FetchXml serializer
using System.Xml.Linq;
namespace Playground
{
public class FetchUtil
{
private static readonly Type[] SimpleTypes = new Type[] { typeof(string), typeof(DateTime), typeof(Enum), typeof(decimal), typeof(Guid) };
public static XElement ToXml(string rootName, object? x, XElement? root = null)
{
if (x == null) { return new XElement(rootName); }
@rezanid
rezanid / powerplatform-dialogs.js
Created December 28, 2021 13:55
Display model-driven custom page as dialogs in Power Platform
/* This function uses Navigation API to display a centered dialog. */
/* Simple parameters are used instead of object to make the function compatible with command bar parameters. */
function displayDialog(rowId, tableName, pageName, title, contentWidth, contentHeight, primaryControl) {
const parseSize = (str, defaultStr) => (str || defaultStr || "500px").match(/([\d\.]*)(.*)/).splice(1,2);
let [w, wUnit] = parseSize(contentWidth);
let [h, hUnit] = parseSize(contentHeight);
var pageInput = {
pageType: "custom",
name: pageName,
entityName: tableName,
@rezanid
rezanid / KnockoutJS-ComputedField.ts
Created November 26, 2020 12:01
How to define a computed property in ViewModel, KnockoutJS, TypeScript
module SampleModule {
export class SampleComponent {
isValid: KnockoutComputed<boolean>;
//...
constructor(public element) {
//...
this.isValidConnectAs = ko.computed<boolean>({
owner: this,
read: () => {
@rezanid
rezanid / Git-Cheatsheet.md
Last active November 18, 2020 12:36
Git Cheat Sheet

When you have one remote

Commands can be shorter when you have only one remote Git server.

Fetch

git fetch

Checkout

git checkout name-of-the-remote-branch

Example output: