Thursday, July 28, 2022

Regarding (Advanced Lookup) Tables filtering in MSCRM

Scenario: Need to filter the Regarding (Advanced Lookup) Tables.

Step 1. Check Lookup schema name




Step 2. Check loaded tables in Lookup


Step 3. Click on Advanced Lookup 

Step 4. You can find list of Tables

Step 5. I want to show only 'account','contact','lead','msdyn_warehouse','msdyn_vendor','incident' in the Table list.

Step 6. I have written JS

function setCustomFilter(context)
    {
        debugger;
        var formContext = context.getFormContext();
        var lookup = formContext.getControl("regardingobjectid");
 
        //check if multiple type dropdowns enabled for this lookup
        if (lookup.getEntityTypes().length > 1) {
            lookup.setEntityTypes(['account','contact','lead','msdyn_warehouse','msdyn_vendor','incident']);            
        }
    }

Step 7. Triggering above function on form load.

Output:

On form load, It will load only 6 entity (table)s records.


here you can find the list of tables.




*** Thank you










Sunday, July 24, 2022

Custom Workflow Activity in Dynamics 365

Step 1- Create New Project

In Visual Studio create a new project of type Class Library & select framework version 4.7.1. This might change for future versions.

Step 2 - Add Required Packages

using System;

using System.Activities;

using Microsoft.Xrm.Sdk.Workflow;

Step 3 - Create Class with name of CustomePlugin 

namespace Banne.Autonumber.BannePlugins

{

    public class CustomePlugin : CodeActivity

    {    

     }

}

Step 4 - Add Input/Output Parameters

using System;

using System.Activities;

using Microsoft.Xrm.Sdk.Workflow;

namespace Banne.Autonumber.BannePlugins

{

    public class CustomePlugin : CodeActivity

    {

        [RequiredArgument]

        [Input("Input Text")]

        public InArgument<string> InputText { get; set; }

        [Output("Word Count")]

        public OutArgument<int> CountOfWords { get; set; }

        protected override void Execute(CodeActivityContext context)

        {

            this.CountOfWords.Set(

                context,

                this.InputText.Get<string>(context).Split(

                    new char[] { ' ', '\r', '\n' },

                    StringSplitOptions.RemoveEmptyEntries).Length);

        }

    }

}

Step 5 - Signing the Assembly


Go to properties then find Signing option. Choose sign the assembly and give key.



Step 6 - Register the Assembly in Dynamics 365



Step 7 - Consuming Custom Workflow Activity in Workflow Process

This workflow calling customeplugin and updating the records

Fig1. add custom plugin step

 


Fig2. add update step


Fig 3. Set Input value for Custom Plugin


Fig4. Set output value from Custom Plugin







Testing the Workflow

Calling workflow to find the total number of words in Name filed contains

Output:






Sunday, July 17, 2022

Microsoft Dynamics 365 CRM Java Script(JS) Basics

 1. Lock or unlock field value

  • formContext.getControl("abc_quantity").setDisabled(true); 
  • formContext.getControl("abc_quantity").setDisabled(false); 

2. Get Value in string format

  • var name=formcontext.getAttribute("abc_name").getValue();

3. To set notification

  • formcontext.getControl("abc_CGST").setNotification("cgst is mandatory","cgstnotifiocation"); 

4. To clear notification

  • formcontext.getControl("abc_cgst").clearNotification("cgstnotifiocation"); 

5. To get time

  • var ordervaliditydate=formcontext.getAttribute("abc_ordervalidity").getValue().getTime();

6.  To get the difference, we have to use this

  • var Days=timediffernce/(1000*60*60*24); 

7. get selected option set value name

  • Var OptionsetSelectedName=formcontext.getAttribute("abc_deliveryrequiredfrom").getText();

8. to set value on the field

  • formcontext("abc_name").setValue(pavan);

9. To show alert for the user

  1. alert(enter valid number);
  2. Xrm.Navigation.openAlertDialog(error.message)

10. Get active stage name of BPF

  • formContext.data.process.getActiveStage().getName();

11. Get entity name

  • formContext.data.entity.getEntityName();

12. Active BPF ID

  • formContext.data.process.getActiveProcess().getId();

13. Get form type

  • var formType=formContext.ui.getFormType();

14. To add Custom View

  • formContext.getControl("abc_warehouse").addCustomView("{00000000-0000-0000-0000-000000000001}","msdyn_warehouse","CustomView",fetchXML,layoutXml,true)

15.  Get Lookup 

  • var LookUpValue=formcontext.getAttribute("abc_product").getValue();// get Lookup name
  • var LookupGUID=LookUpValue[0].id; // get GUID of the record
  • var newLookupGUID=LookupGUID.replace("{","").replace("}",""); //replace braces on GUID
  • var LookupName=LookupValue[0].name; 
16. Set Lookup      
  • var lookupValue = new Array();
  • lookupValue[0] = new Object();
  • lookupValue[0].id = "{727504ed-64c5-4bc8-ac22-0a3071c427e}"; // GUID of the lookup id
  • lookupValue[0].name = "Contoso"; // Name of the lookup
  • lookupValue[0].entityType = "contact"; //Entity Type of the lookup entity
  • formContext.getAttribute("FieldName").setValue(lookupValue); // Replace the lookup field
17. To set visible 
  • formcontext.getControl("abc_gst").setVisible(true); // to show
18. To set hide
  • formcontext.getControl("abc_gst").setVisible(false); // to hide
19. Terminating the js execution
  • return;
20. To get Form Context
  • var formcontext=executionContext.getFormContext();
21. Get subgrid ID
  • var gridControl = document.getElementById(subgridName);
22.  Prompt
  • var userText = prompt("Please enter your Remarks below", "Write here...");
23. Show Progress Indicator
  • Xrm.Utility.showProgressIndicator("Please wait while the request is being processed.");
24. Close Progress Indicator
  • Xrm.Utility.closeProgressIndicator();
25. Show Tabs
  • formContext.ui.tabs.get("ReportingTab").setVisible(true);
26. set option set value
  • formContext.getAttribute('abc_visittype').setValue(799240001);
27. set Required Level
  • formContext.getAttribute("abc_latitude").setRequiredLevel("required");
28. get User Roles
  • formContext._globalContext.getUserRoles();
29. get Current Item (selected form)
  • formContext.ui.formSelector.getCurrentItem().getLabel();
30. Get Total Records Count in Sub-Grid 
  1. var gridContext = formContext.getControl("Gift_Distribution"); //Sub-Grid Name
  2.  let TotalCount = gridContext.getGrid().getTotalRecordCount(); // Collect Total Row Count

Power Apps Portals Navigations

  1. Portal Navigation Settings:    

-> Go to Web link Sets->add Links (Web Links)
















add required web link here










Output:


2. Add child Web links on Primary Navigation:

Go to Web Link set-> Links (Web Links)









Output: