Saturday, October 16, 2021

Share Records with Permission using Web API in Dataverse or MSCRM


Introduction 

In this Blog we will see how to share a Row/Record with permission using Web API JavaScript


Scinario:

Consider we have an Contact Field in Account Entity. then On save of record i need to take the Respective Contact and Share the Account Owner to Contact Owner.


Parameter For Sharing Record

Read : ReadAccess

Write : WriteAccess

Append : AppendAccess

Append To : AppendToAccess

Create : CreateAccess

Delete : DeleteAccess

Share : ShareAccess

Assign : AssignAccess


JavaScript code for Implementing:


function shareUserOrTeamtoRecord(executionContext) {
    var context = executionContext.getFormContext();
    var target = {
        "contactid": "ACAAB842-21C7-E811-A96F-000D3A16A41E", // Pass your respective Record id
        "@odata.type": "Microsoft.Dynamics.CRM.contact" // Pass your respective Entity Logical name record type
    };

    // Sharing with Team
    var principalAccess = {
        "Principal": {
            "teamid": "d272654b-57f5-4564-8d0b-36d0d4c426c4",
            "@odata.type": "Microsoft.Dynamics.CRM.team"
        },
        "AccessMask": "ReadAccess, WriteAccess"
        //Access Mask Sample "ReadAccess, WriteAccess, AppendAccess, AppendToAccess, CreateAccess, DeleteAccess, ShareAccess, AssignAccess"
    };

    // Sharing with User
    var principalAccess = {
        "Principal": {
            "teamid": "d272654b-57f5-4564-8d0b-36d0d4c426c4",
            "@odata.type": "Microsoft.Dynamics.CRM.team"
        },
        "AccessMask": "ReadAccess, WriteAccess"
        //Access Mask Sample "ReadAccess, WriteAccess, AppendAccess, AppendToAccess, CreateAccess, DeleteAccess, ShareAccess, AssignAccess"
    };

    var parameters = {
        "Target": target,
        "PrincipalAccess": principalAccess
    };

    var req = new XMLHttpRequest();
    req.open("POST", context.getClientUrl() + "/api/data/v9.0/GrantAccess", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                //Success - No Return Data - Do Something
            } else {
                var errorText = this.responseText;
                //error response
            }
        }
    };
    req.send(JSON.stringify(parameters));
}


Conclusion:


That's it :) This is how we need use above JavaScript to implement Record Sharing using WebApi.

 


Tuesday, October 12, 2021

Open URL in PowerApps/Dataverse/MSCRM form Using JavaScript


Introduction:


In this blog we will see how to write Javascript to Open URL in PowerApps/MSCRM/Dataverse Environment.


Implementation Steps:

 

Syntax:

 

 

Xrm.Navigation.openUrl(url,openUrlOptions)

 

 

 

Consider am having a field in an Account Entity Called URL. Then in Onload of Page, if URL Field Contains Data Open another Page with URL

 

To Begin with i created a Field Called URL in Account Form

rampprakash_0-1634019498527.png

 

Then Create a WebResource File with Type as JS

rampprakash_1-1634020115162.png

 

function openURLOnLoad(executionContext) {
    var formContext = executionContext.getFormContext();
    if (formContext.getAttribute("cr608_url").getValue() != null) {
        var URL = formContext.getAttribute("cr608_url").getValue();
        var openUrlOptions = {
            height: 800,
            width: 800
        };
        Xrm.Navigation.openUrl(URL, openUrlOptions);
    }
}

 

Then Call the function in OnLoad Opearation

 

rampprakash_2-1634020208004.png

 

Save and then Publish

 

Create a Record in Account Entity 

rampprakash_3-1634020285670.png

 

Save then Refresh the Form

 

rampprakash_4-1634020327591.png

 

That's it :slightly_smiling_face:


Video For your Reference: Watch it and Subscribe it :slightly_smiling_face:




Friday, October 8, 2021

How to Create and Customize Sitemap in Model Driven App / Dataverse / MSCRM


Introduction:

In this Blog, we will see how to Create and Modify Site map in Model Driven Apps/ Dataverse Environment


Implementation Steps:

 

Consider you have 2 Different teams available in your Organization, 

 

1. Sales Team

2. Pay Roll Team

 

If Sales Team Logged into Dataverse environment they need to see only their Respective Entities in Site Map, the same way for Pay Roll Team as well.

 

So Come across this scenario, we can create 2 different Model-Driven Apps and we can share the same to Respective Teams.

 

To Create a Model-Driven Apps

1. Navigate to https://make.powerapps.com

 

2. Click On Apps

 

rampprakash_0-1633688339817.png

 

3. Then Select Model Driven Apps

 

4. Once You Selected it will prompt you with two option, 

          a. Classic Mode

          b. Modern App Designer.

 

rampprakash_2-1633688510980.png

 

 

Lets Start looking Classic Mode

 

1. Once You selected ok for Classic Mode it will take you to App Creation page, Enter your App Name, Unique name will be auto populated from App name.

 

If you have any Images you can select and click on Done

 

rampprakash_3-1633688552428.png

 

2. App Designer Page will gets loaded, Click on site map to Add the Entities

 

rampprakash_4-1633688694622.png

 

3. Enter the Area name, Group name 

 

rampprakash_5-1633688734468.png

 

4. Then Click On New Subarea and Select the Entities

 

rampprakash_6-1633688789889.png

 

That's it, Click on Save and Publish then Run the App to view the Designers

 

b. Modern App Designer

 

1. Once you select Modern App Designer, You will be request to Enter Model Driven App name

 

rampprakash_7-1633688907949.png

 

2. Click Add Page button in the Body of screen

 

3. Then Select Weather you want Table based View and form / Dashboard / Custom

 

rampprakash_8-1633688950188.png

If you select Table view and form pages you will be popped up with below screen. Select the Entities and Click Add by Selecting Show in Navigation

 

rampprakash_9-1633689004253.png

After clicking ok you can see the selected Entities in the Navigation

 

rampprakash_11-1633689157979.png

 

To add a new page click Add Page and you will be Popped with the Selection Screen Again

 

rampprakash_12-1633689196996.png

 

That's it.. this is how we need to Create Model Driven App in Dataverse Environment.

Tuesday, October 5, 2021

How to Use Open Entity Form in Dataverse Environment


Introduction:


In this blog we will see how to Open Entity/Quick Create Form from Dataverse/Model Driven Apps


There are two type of Forms Available

1. Main Form

2. Quick View Form

 

1. Main Form:

 

Consider you have a Ribbon Button and on Click on Button you want to Open a Main Form. So for that you can write the below JavaScript command to achieve the same


var parameters = {

};

parameters["cr608_logicalName1"] = Value1ForLogicalName1;

parameters["cr608_logicalName2"] = Value2ForLogicalName2;


Xrm.Utility.openEntityForm("cr608_EntityLogicalName", null, parameters);

 

2. Quick View Form:

 

Consider I have an account Entity and I want to Create an Contact Against that Account for that

 

First Retrieve Account Value and store in a Temporary Variable.

 

var retrieveAccountValue = null;

var accountId = null;

var account = primaryControl.getAttribute("parentaccountid"); // you can use formContext from Form. From Ribbon you need to pass Primary Control as Parameter

if (account != null) {

  retrieveAccountValue  = account.getValue();

  if (retrieveAccountValue  != null) {

    accountId = accountValue[0].id;

  }

}

 

Then Create a Variable to set the Account Values

 

var parentAccountForContact = {

  entityType: "account",

  id: accountId

};

 

then you can Call the below code to open a Quick Create Form

 

// Create a Parameter

var parameters = {};

//Open Quick Create Form

Xrm.Utility.openQuickCreate("contact", parentAccount, parameters).then(function (ValueOutput) { successCallback(ValueOutput); }, function (error) { errorCallback(error);});

// Success Call

function successCallback(success) {

  alert("Success");

}

// Error Call

function errorCallback(e) {

  alert("Error: " + e.errorCode + " " + e.message);

}

 

That's it


Conclusion:


This is how we need to user Open Entity Form in DataVerse/Model-DrivenApps/CRM Environment.

Monday, October 4, 2021

Scan Multiple Barcode at Once using PowerApps


Introduction :


In this Blog, we will see step by step implementation of how to Scan Multiple Barcodes at once and patch it to SharePoint


Implementation Process:

 

SharePoint:

 

1. Navigate to office.com

 

2. Click SharePoint (if SharePoint List Already Available Copy the List Name else follow from Step #3)

 

3. Click Create Site then Team Site

 

rampprakash_0-1633345239378.png

 

4. Site then Input the Site Name and Owner and Privacy Setting as PUBLIC

rampprakash_1-1633345304964.png

 

4. Click Next for completion of Site Creation

 

rampprakash_2-1633345367446.png

 

5. Click New then Click List and Select Blank List then Click Next and Input the Name and Create.

 

6. Copy the SharePoint Browser URL.

 

PowerApps:

 

1. Navigate to https://make.powerapps.com

 

2. Then Click on Apps

 

3. Click New and Select Canvas App

 

4. Once Page Opened Click on App and write the below Code

 

              getMultipleBarCodes --> to Collect Values after Scanning

 

ClearCollect(getMultipleBarCodes,Blank())

rampprakash_0-1633345525871.png

 

5. Add a Gallery and Set the Item for that Gallery as getMultipleBarCodes

 

rampprakash_1-1633345627696.png

 

6. Add a Barcode Button Insert --> Media --> Barcode Scanner

 

rampprakash_2-1633345683083.png

 

7. Select the Scan Button and in On Scan Operation write the below code ( if the Scanned code already exists then Throw Error else Collect the information)

 

If(CountRows(Filter(getMultipleBarCodes,Value=BarcodeScanner1.Value))>0,Notify("Scanned Barcode already Exists"),Collect(getMultipleBarCodes,BarcodeScanner1.Value));

 

8. Click on Data source then Select SharePoint then Input the copied URL and select the List

 

9. Click OK.

 

10. Add a Button 

 

rampprakash_3-1633346028817.png

 

11. Rename as Submit and write the below code in On Select of that button

 

ForAll(getMultipleBarCodes,Patch('BarCode List',Defaults('BarCode List'),{Title:Value}))

 

12. Save and Publish the App.

 

That's it. This is how we need to use Multiple Barcode Scanning with PowerApps.

 

Video for your Reference : To Subscribe

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...