Design a site like this with WordPress.com
Get started

How to use God Mode without having the Level Up extension using  Developer tools(F12)  that any browser😜 in MS Dynamics 365 CRM.

Press F12, navigate to the Console section and run the following code. It will do exactly the same as God Mode

Xrm.Page.data.entity.attributes.forEach(function(attr) {attr.setRequiredLevel('none')} );

Xrm.Page.ui.controls.forEach(function(c){ c.setVisible(true);
      if (c.setDisabled) {
        c.setDisabled(false);
      }
      if (c.clearNotification) {
        c.clearNotification();
      }});


Xrm.Page.ui.tabs.forEach(function(tab){
      tab.setVisible(true);
      tab.setDisplayState('expanded');
      tab.sections.forEach(function(section) {section.setVisible(true)});
    });

Thanks for taking the time to read my blog, I hope you found it useful and informative. If you enjoyed the content, please consider subscribing to my YouTube channel for more videos on related topics. Here’s the link to my channel: https://www.youtube.com/channel/UCulwrFxBkHWdl7jBH9tCD8w. Thanks for your support!

What does this ${} syntax do?

The ${} syntax is typically used to interpolate variables or expressions within a string or template literal in various programming languages.

Sometimes called template literals or template strings , this format is another way to type out a string making use of (called a backtick or grave accent). It can be used easily as a replacement.

For example:(1)

var name = "Mohammed Shafiuddin";
var message = `Hello ${name}!`;
console.log(message); 
// Output: "Hello Mohammed Shafiuddin!"

In this example, the value of the name variable is interpolated into the string using ${name}. The resulting string, Hello Mohammed Shafiuddin!, is then assigned to the message variable and logged to the console

The ${} syntax is also used in other contexts, such as in shell scripting or in build tools like Make, to reference environment variables or command-line arguments. In these cases, the ${} syntax is used to expand the value of the variable or expression enclosed within the curly braces.

For example: (2)

To retrieve a list of contacts for a given account:

var accountId = Xrm.Page.getAttribute("parentaccountid").getValue()[0].id;

var fetchXml = `
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
        <entity name='contact'>
            <attribute name='fullname' />
            <attribute name='emailaddress1' />
            <order attribute='fullname' descending='false' />
            <filter type='and'>
                <condition attribute='parentcustomerid' operator='eq' value='${accountId}' />
            </filter>
        </entity>
    </fetch>
`;

var encodedFetchXml = encodeURIComponent(fetchXml);

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getClientUrl() + "/api/data/v9.0/contacts?fetchXml=" + encodedFetchXml,
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=*");
    },
    success: function (data, textStatus, xhr) {
        // Handle the retrieved contacts data
    },
    error: function (xhr, textStatus, errorThrown) {
        // Handle any errors
    }
});

In this example, the ${accountId} syntax is used to interpolate the accountId variable into the FetchXML query string. The accountId variable is retrieved using the Dynamics 365 CRM JavaScript object model, and is used to filter the list of contacts to only those that have the specified account as their parent customer.

The resulting FetchXML query string is then used to construct a URL for an AJAX request that retrieves the contacts data from the Dynamics 365 CRM server.

Thanks for taking the time to read my blog, I hope you found it useful and informative. If you enjoyed the content, please consider subscribing to my YouTube channel for more videos on related topics. Here’s the link to my channel: https://www.youtube.com/channel/UCulwrFxBkHWdl7jBH9tCD8w. Thanks for your support!

Business Process Flow(BPF) useful validations Using Jscript in ms dynamics 365 CRM.

Inspired by a suggestion from my colleague, I am excited to share this blog with you on Business Process Flows (BPF).

When a form displays a business process flow control in the header, additional controls gets added for each attribute that is been displayed in that BPF.

These controls hold unique names like:header_process_.

So using this control we can write script around these fields.

The Controls displayed in the form header are also accessible and hold unique name like:header_.

Show/Hide field:The setVisible function is used to either show or hide the field based on its argument (true for show and false for hide).

We can show and hide business process flow fields using JavaScript in Microsoft Dynamics 365 CRM using the following code:

// To show the business process flow field
Xrm.Page.getControl("header_process_statecode").setVisible(true);

// To hide the business process flow field
Xrm.Page.getControl("header_process_statecode").setVisible(false);

Make the field Read only:

We can make a business process flow field read-only using JavaScript in Microsoft Dynamics 365 CRM with the following code:

Xrm.Page.getControl("header_process_dummyField").setDisabled(true);

Replace this value with the actual logical name of your field.

The setDisabled function is used to disable the field, making it read-only.

The argument passed to the function is true, indicating that the field should be disabled.

Filter a lookup field:

You can filter a lookup field based on the value of another field in a business process flow using JavaScript in Microsoft Dynamics 365 CRM.

Here is an example code that demonstrates how to do this:

//Get the value of the first field
var firstFieldValue = Xrm.Page.getAttribute("first_field").getValue();

//Get the lookup field to be filtered
var lookupField = Xrm.Page.getAttribute("lookup_field");

//Check if the first field has a value
if (firstFieldValue) {
    //Create the filter array
    var filterArray = [];

    //Add the filter condition to the array
    filterArray.push(new Xrm.Sdk.FilterExpression("field_to_filter", Xrm.Sdk.ConditionOperator.Equal, firstFieldValue[0].id));

    //Set the filter for the lookup field
    lookupField.setFilter(filterArray);
}
else {
    //Clear the filter for the lookup field
    lookupField.setFilter(null);
}

Get/Set Value:

We can get and set the value of a business process flow field using JavaScript in Microsoft Dynamics 365 CRM.

Here is an example code that demonstrates how to do this:

//Get the value of a field
var fieldValue = Xrm.Page.getAttribute("header_process_descriptions").getValue();

//Set the value of a field
Xrm.Page.getAttribute("header_process_descriptions").setValue("new_value");

The getAttribute function is used to get a reference to the field, and the getValue and setValue functions are used to get and set the value of the field, respectively.

The argument passed to the setValue function is a string, "new_value", which represents the new value that you want to set for the field.

Lock and Unlock Field:

We can lock and unlock a business process flow field using JavaScript in Microsoft Dynamics 365 CRM.

//Lock a field
Xrm.Page.getControl("field_logical_name").setDisabled(true);

//Unlock a field
Xrm.Page.getControl("field_logical_name").setDisabled(false);

field_logical_name is the logical name of the field that you want to lock or unlock. Replace this value with the actual logical name of your field.

The getControl function is used to get a reference to the field, and the setDisabled function is used to set the field to be either disabled (locked) or enabled (unlocked).

The argument passed to the setDisabled function is true to lock the field, or false to unlock the field.

I hope you found this information helpful and it answered your questions. If you have any further questions, feel free to ask. Thank you for reading!🙏

How to Go Previous page using jQuery in MS CRM Power Portals.

We can use the following code to go back to the previous page in MS CRM Power portals using jQuery

$(document).ready(function() {
   $('.class/#Id').click(function() {
      window.history.back();
   });
});

This code binds a click event to an element with a class of “back-button”. When that element is clicked, the window.history.back() function is executed, which will navigate back to the previous page in the browser history.

How to Lock/Unlock fields using Jscript in MS Dynamics 365 CRM

Using below code we can Lock/Unlock fields using JScript in MS Dynamics 365 CRM

function lockUnlockAlphaBetaFields(executionContext) {
    //Initiated Form Context.
    var formContext = executionContext.getFormContext();
    //Getting Value From Field 
    var type = formContext.getAttribute("New_Alpha").getValue();
    //Condition If Account Name Is Null.
    if (type === null || type === undefined) {
        //Using SetVisible property for locking field Beta.
        formContext.getControl("New_Beta").setDisabled(true);
    }
	else{
		//Using SetVisible property for Unlocking field Beta.
        formContext.getControl("New_Beta").setDisabled(false);
	}
}

How to Get Users with Security roles using fetch xml in MS Dynamics 365 CRM

Using Below Fetch XML we can get the Users with Security Roles in MS Dynamics 365 CRM

<fetch>
  <entity name="systemuser">
    <attribute name="fullname" />
    <link-entity name="systemuserroles" from="systemuserid" to="systemuserid">
      <link-entity name="role" from="roleid" to="roleid">
        <attribute name="name" />
        <attribute name="roleid" />
        <filter>
          <condition attribute="roleid" operator="eq" value="00000000-0000-0000-0000-000000000000" uiname="System Administrator" uitype="role" />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch>

How to Enable Rich Text Editor in MS CRM Power Apps Portals.

Step 1: Go to make.powerapps.com and Open the form which you are using to contact record in PowerApps Portal and add the rich text control as shown below images.

Step 2: Save and Publish the form.

Step 3: Go to Portal management App and open contact Basic form and Go to Related –> Basic Form Metadata –> Click on New Basic Form metadata.

Step 4: Select Type as Attribute , Attribute Logical Name as description (select the column name from drop-down) and Control Style as Code Component.

Step 5: Add table permissions for the rich text attachment table.

Table Name select as Rich Text Attachment (msdyn_richtextfile)

Add Web Roles

Step 6: If you want to store images as base 64 strings directly in the column that you’ve configured to use the rich text editor control, you need to configure the control by using a JSON configuration file. Set disableImages and disableDefaultImageProcessing to true to allow images to be rendered consistently across all clients. Using this method doesn’t require the global table permission on the rich text attachment (msdyn_richtextfile) table.

Step 7: Add web API site setting [Go to Site Settings and Create the following site settings: enter the name, your website, and the value of true, and then select Save & Close.]

Site setting nameValue
Webapi/msdyn_richtextfile/enabled
true
Webapi/msdyn_richtextfile/fields*

Step 8: Clear cache/ Synch Configuration and Refresh the Portal url.

Step 9: Lets check the Rich Text is working as expected or not.

Hence Rich Text Box working as expected.

Note:

  1. On a read-only form, the rich text editor displays the content with formatting and images. The content can be read, but not edited or updated.
  2. If you are using a separate form to view and edit the record in PowerApps Portal, you need to add a code component to those forms as well.
  3. The rich text editor control can be used with single or multi-line text columns.

How to remove blank lines from a NotePad++

There are multiple method to Delete/Remove the empty lines.

Method 1:

  1. Open Notepad++ and click Edit from the header menu —> Select Line Operation–> Remove Empty Lines (Containing Blank characters).

Method 2:

  1. Open Notepad++ and the file you want to edit.
  2. In the file menu, click Search and then Replace.
  3. In the Replace box, in the Find what section, type ^\r\n (five characters: caret, backslash ‘r’, and backslash ‘n’). Leave the Replace with section blank unless you want to replace a blank line with other text.
  4. In the Search Mode section, make sure Regular expression is selected as shown in below image.
  5. Click the Replace All button to replace all blank lines.

Hope it helps 😉😉 to you guys, if you struck anywhere add your comments in comment box section will help you out to fix the issue.

How to get the Instance Web API Logical Name and Object Code(HTTP REST API providing access to this instance of Dynamics 365)

Step 1: Go to Settings—> Customizations —> and click on Developer Resources

Step 2: From Instance Web API Copy the Service Service root URL.

Step 3: Open new Tab and there paste https://orgb3b35678.api.crm.dynamics.com/api/data/v9.2/ copied URL and search

Step 4: If we need Data of entity append

https://orgb3b35678.api.crm.dynamics.com/api/data/v9.2/contactsEntity logical name

Step 5: we can use the below text to get the ObjectTypeCode and LogicalName.

/EntityDefinitions?$select=LogicalName,ObjectTypeCode

For Example

https://orgb3b35678.api.crm.dynamics.com/api/data/v9.2/EntityDefinitions?$select=LogicalName,ObjectTypeCode

Hope it helps 😉😉 to you guys, if you struck anywhere add your comments in comment box section will help you out to fix the issue.

How to prevent Inspecting (F12) the elements in MS CRM Power Portals.

Scenario: we need to restrict/prevent inspect the element in my page

Step 1: Write code as below

$(document).ready(function () { 
document.addEventListener('contextmenu', function(e) {
  e.preventDefault();
});
document.onkeydown = function (e) {
  if (e.keyCode === 123) {
    return false;
  }
  if (e.ctrlKey && e.shiftKey && e.keyCode == "I".charCodeAt(0)) {
    return false;
  }
  if (e.ctrlKey && e.shiftKey && e.keyCode == "C".charCodeAt(0)) {
    return false;
  }
  if (e.ctrlKey && e.shiftKey && e.keyCode == "J".charCodeAt(0)) {
    return false;
  }
  if (e.ctrlKey && e.keyCode == "U".charCodeAt(0)) {
    return false;
  }
};
});

Step 2: Paste the code as shown below.

Step 3: Sync Configuration and Browse website

Step 4: Now we can test the functionality.

Now i am not able to inspect the elements our functionality is working as expected.

Hope it helps 😉😉 to you guys, if you struck anywhere add your comments in comment box section will help you out to fix the issue.