Thursday 20 July 2023

Hide New... button on lookup controls in model-driven apps

 The 'New ...' button is shown upon opening the lookup search dialog whenever the logged in user has at least user create privilege on a dataverse table. We recently had a requirement to prevent users from creating a new record from the lookup. This was required only on a specific form. The users should otherwise be able to create the record from other areas of the model driven app.


Unfortunately, there is no way of hiding the out of the box button from the user interface via the form editor and to remove the create privilege did not suit our purpose:


Luckily there is an option within the form XML that helps us to achieve the desired outcome. Adding the tag <IsInlineNewEnabled>false</IsInlineNewEnabled>, will remove the button for all users no matter what their privileges allow. This tag is usually not present on the form xml. This solution is supported and works for current Power Platform model-driven apps. Should work for on premise as well but haven’t tried it.


Steps:

  1. Create an unmanaged solution containing only the required form.

  2. Locate the lookup control based on its schema name in customizations.xml

  3. Add IsInlineNewEnabled tag to control's parameters collection

  4. Zip the contents of the extracted folder including your modified customizations.xml

  5. Import the newly created solution zip file and publish all changes.

  6. Verify that the button is not shown.

Sample schema of the lookup is as shown below (Parameters of your lookup instance might vary). The new tag is highlighted:



If all goes as expected, then the result should be as shown below:


Wednesday 14 June 2023

Read Values from SubGrid through JavaScript

   var gridContext = formContext.getControl("Subgrid_new_Applications");



      

            var appRows = gridContext.getGrid().getRows();


            //var RowCount = appRows.getLength();


        appRows.forEach(function (row, i) {

            var gridColumns = row.data.entity.attributes;

            console.log("Application Id =" + row.data.entity.getId());

            gridColumns.forEach(function (column, j) {

                var atrName = column.getName();

                var atrValue = column.getValue();

                console.log(atrName + ":" + atrValue);

            });


        });

Tuesday 6 June 2023

Dynamics 365 – Hide/Disable/Edit Business Process Flow Fields using JavaScript

 In Dynamics 365, Business Process Flow attributes are just like Form attributes. You can use most of the controls in the same way as you normally do for Form attributes. Let’s look at the most common ones together.

Get Business Process Flow attribute control using Javascript

To get attributes Add “header_process” before schema name of field. Let’s say your attribute schema name is “cm_myattribute“.

1
2
3
4
5
function BpfControls(executionContext) {
    var formContext = executionContext.getFormContext();
    var bpfControl = formContext.getControl('header_process_cm_myattribute');
    var bpfAttribute = bpfControl.getAttribute();
}

Set attribute value for Business Process Flow using Javascript

1
2
3
4
5
6
7
8
9
function BpfControls(executionContext) {
    var formContext = executionContext.getFormContext();
    var bpfControl = formContext.getControl('header_process_cm_myattribute');
    var bpfAttribute = bpfControl.getAttribute();
 
    if (bpfAttribute != undefined) {
        bpfAttribute.setValue("myValue");
    }
}

Hide field in a Business Process Flow using Javascript

1
2
3
4
5
6
function BpfControls(executionContext) {
    var formContext = executionContext.getFormContext();
    var bpfControl = formContext.getControl('header_process_cm_myattribute');
 
    bpfControl("header_process_cm_myattribute").setVisible(false);
}

Set field Required in a Business Process Flow using Javascript

1
2
3
4
5
6
7
8
9
function BpfControls(executionContext) {
    var formContext = executionContext.getFormContext();
    var bpfControl = formContext.getControl('header_process_cm_myattribute');
    var bpfAttribute = bpfControl.getAttribute();
 
    if (bpfAttribute != undefined) {
        attribute.bpfAttribute("required");
    }
}

Set field Disable in a Business Process Flow using Javascript

1
2
3
4
5
function BpfControls(executionContext) {
    var formContext = executionContext.getFormContext();
    var bpfControl = formContext.getControl('header_process_cm_myattribute');
    bpfControl.setDisabled(true);
}

Hide New... button on lookup controls in model-driven apps

  The 'New ...' button is shown upon opening the lookup search dialog whenever the logged in user has at least user create privileg...