Archive

Archive for August, 2021

Tip | Model Driven Apps | Client API | setSharedVariable and getSharedVariable

As we know Client-side scripting using JavaScript is one of the ways to apply custom business process logic for displaying data on a form in a model-driven app, In this article lets understand how to pass variables between event handlers (i.e., Different jScript functions registered as event handlers).

Lets understand this by first understanding the Form event pipeline.

Form event pipeline:

  • We can define up to 50 event handlers for each event. Each event handler is executed in the order that it is displayed in the Event Handlers section in the Events tab of the Form Properties dialog box.

setSharedVariable:

  • Sets the value of a variable to be used by a handler after the current handler completes.
  • Syntax : ExecutionContextObj.setSharedVariable(key, value);
    • Ex : ExecutionContextObj.setSharedVariable(“sharedAccountName“, formContext.getAttribute(“name”).getValue());

getSharedVariable:

  • Retrieves a variable set using the setSharedVariable method.
  • Syntax: var sharedVariable = ExecutionContextObj.getSharedVariable(key);
    • Xrm.Navigation.openAlertDialog({ text: ExecutionContextObj.getSharedVariable(“sharedAccountName“) });

🙂

Code Snippet | JScript | Capture BPF Stage Parameters

Below is code snippet to capture the BPF stage parameters up on the ‘Stage’ change using jscript.

function onload(executionContext) {
    var formContext = executionContext.getFormContext();
    // Register event handler on Process Stage Change
    formContext.data.process.addOnStageChange(onStageChange);
}

function onStageChange(executionContext) {
    var formContext = executionContext.getFormContext();
    var stage = formContext.data.process.getSelectedStage();
    // Get Stage Name
    var currStageName = stage.getName();
    // Show Stage Name
    Xrm.Navigation.openAlertDialog({ text: "Current StageName - " + currStageName });

    // Get Stage ID
    var stageID = stage.getID();
    // Get Entity Name
    var stageEntityName = stage.getEntityName();
    // Get Stage Status
    var stageStatus = stage.getStatus();
}
  • Save this script as web resource and register both the ‘onload’ and ‘onStageChane’ functions on form’s onload event.
  • Below is the example of script on Opportunity form.

🙂

Categories: PowerApps Tags: , ,

[Step by Step] Dataverse | Connect Cloud flow with Service Principal (Application User)

By default, Cloud flow Dataverse connectors run under the Owner (i.e., User who created the flow) context. When the flows move to different environment via solutions, connectors run under the user account who imported the Solution.

Making the flows run under interactive user accounts is not recommended as they cause confusion when we check the record’s audit for who updated the record. Its recommended to make the flow run under ‘Application User’, if the calling user can be a fixed account.

In this article lets see how to make the flow run under Application User using Connect the flow using Service Principal option.

High level design:

Following are the steps we gonna go through.

  • App registration in Azure Active Directory (AAD)
  • Create an Application User in Environment.
  • Create a Cloud Flow and connect with Application User.

App registration in Azure Active Directory (AAD)

  • Add a Secret and save the Secret.
  • Copy the Application ID and Tenant ID.
  • Refer this article for the detailed ‘App Registration’ steps.

Create an Application User in Environment

  • Click on ‘New app user’ and select ‘Business Unit’ and ‘Security Role(s)’.
  • Click on ‘Add an app’ and select the App registered in previous section.
  • You should see the ‘Application user’ listed as below.

Create a Cloud Flow and connect with Application User:

  • Connect to Maker portal and create a new Solution.
  • Click on New -> Cloud flow.
  • Click on ‘Connect with Service Principle’.
  • Provide the details captured in Azure Active Directory ‘App Registration’ section and click ‘Create’.
  • Now you should see that in ‘Connection references’ as below.
  • If you go back to the ‘Solution’, you would see a new entry ‘Connection Reference (preview)’ along with the flow.
  • With the ‘Connection Reference (preview)’, we can conveniently move flow to different environment using Solution export and import.
  • Lets proceed and complete the flow, which creates a ‘Contact’ record upon the creation of an ‘Account’.
  • Create an ‘Account’ from the ‘Customer Service Hub’ App.
  • A ‘Contact’ gets created triggered from the flow and Owner would the ‘Application User’.

Notes:
  • You can use ‘Run as’ option and make the ‘Dataverse’ run under one of the highlighted User contexts.

🙂

[Preview Feature] Model Driven Apps | Edit Command Bar

In this article lets explore the ‘Edit Command Bar’ preview feature available in Model Driven Apps designer. But first lets understand the following basics of Command Bar.

  • What are Command Bars?
  • Where do we find them in Model Driven App (i.e., Command bar locations)?

What are Command Bars?

  • Command bars are at the core of every model-driven app and appear in many different locations.
  • The group of commands associated with a specific location make up a command bar.

Command bar locations in Model Driven App:

  • Main grid. This command bar is displayed when using the left-hand navigation of an app to view a full page list of records in this table.
  • Main form. This command bar is displayed on the table’s main forms. This appears at the top of the form and is not the same as the associated view or subgrid view that will appear in different areas of the form.
  • Subgrid view. This command bar is displayed on forms of other tables that render this table’s data within a subgrid.
  • Associated view. This command bar is displayed on the form of a parent table when viewing related data in this table.
  • Quick actions. There isn’t a specialized entry point from the command designer because quick actions are edited from the main grid of the table.

Now that we got the basics, lets explore editing the Command bar.

Using ‘Edit command bar (preview)’:

  • To use ‘Edit command bar (preview)’ feature. Connect to Power Apps portal.
  • Create a new ‘Model-driven app from blank’ and select the ‘Modern app designer (preview)’.
  • Add a Page and link one of your Dataverse Table.
    • I’ve added ‘Student’ table as Page.
  • Now click on ‘…’ of ‘Student’ and click on ‘Edit command bar (preview)’.
  • From the options choose one of the ‘Command Bar’ location you would like to edit.
  • In the next screen, you will get all the available of Commands displayed as below.
    • At this point editing ‘Legacy button is not supported’. Refer the limitations here.
  • I am going to add a new ‘Command’ named ‘Open My Blog’ which opens up an URL.
  • Click on ‘+New command’ and provide details on the right pane.
  • Action property specifies what happens on the ‘Select’ of the ‘Command’. Below are 2 available options.
  • As I need to open URL on the select of my ‘Open My Blog’ command. Under Action’ choose ‘Run formula’ and in the formula bar add ‘Launch()’ Power Fx as below.
  • Click ‘Save and Publish’ and ‘Play’.
  • On your App, you should see the command and on select it redirects to the provided URL.

Refer the docs link for more details.

🙂

Categories: PowerApps Tags: ,

Dynamics 30 days trial | Changes in subscription steps

August 3, 2021 2 comments

As we know trials.dynamics.com would allow us to subscribe to Dynamics 30 days trial using our personal email (i.e., Live.com, etc…). With the recent changes, trials.dynamics.com redirecting us to the following portal.

Up on clicking ‘Try for free’ its mandating us to enter “Either Work or school email ID”.

Which means we can’t sign up using personal email. But wait, when you give the personal email and try, you get an error message and a ‘Click here’ link, which allows you to sign up using personal email.

Click on ‘Click here’ and you will be redirected to the classic ‘Sign up’ screen.

Alternately you can directly use this link to go to the above Sign up page directly by passing new portal.

Hope this info saves you sometime 🙂