Upload,Download ,Edit, Delete Document , Working with Notes in D365 Portal.

Sometime we have a requirement like user can able to Upload, Download ,Delete ,Edit documents from portal. In this post i will show you how to achieve this requirement. we have Two ways to achieve this scenario. I will explain both of ways one by one.

Before moving forward, here i am considering, you have basic knowledge of entity form (like Create/Update/Delete records). If you do not know about this then click Here to know that.

Method 1 : This Method is used when we Edit/Update the records from Portal. We can not used this when we create the record. 


Step 1: Open CRM and add Notes/Timeline section in your CRM form on which you want to apply Notes from portal.

Step 2: Make Notes the default tab.

Step 3: Now open Entity form in portal (portal > entity form) on which you want to add Notes section. Mode of Entity Form should be Edit. (Because this method is used in case of when we update the records from portal )

Step 4: Scroll down your Entity Form record and reach at Entity Form Metadata Sub-grid.
Step 5: Click on + icon to create a new Entity Form Metadata.
Type: It must be Notes.
Create Enabled: Set it true to create note from Portal.
Edit Enabled: set it true to edit the notes from Portal.
Delete Enabled: set it true to delete the notes from Portal.

Step 6: Now scroll up Entity Form and make sure Entity Permission checkbox should be checked.

Step 7: Now go to Portal > Entity Permission.

Step 8: Create a new Entity Permission.
Name: Give the name of permission.
Entity Name: Select Note entity.
Website: Select website on which you are working.
Scope:  Select Global Scope and checked all check-boxes.


Step 9: Scroll Down the Record and reach Web Role Subgrid.

Step 10: Add web role here for this Entity Permission. The Web Role associated to the Portal Contact should also be associated with this Entity Permission. here i am admin that's why i added admin role.

Now Check in portal. Hope you are able to see Add Notes button as show in below Screenshot.

When you click on Add Notes, a popup will come, here you can give your Description and attach any documents.

After attach document, Now you are able to see your Notes/Documents.

 Now to Delete or Edit the Document, Click on icon as show in below screenshot. Here you can Delete and Edit your attachment also.


Now to Download the Document, just click on document.


Method 2: It can be used when we Create or Update the records from portal.


Step 1: Now open Entity Form record from which you want to attach documents from portal.

Step 2: Scroll down the record and reach at Add Attach File Section.
Attach File: Select this option to upload document from portal.
Allow Multiple Files: Select this option to upload multiple file in one time.
Attach File Storage Location: Give Note attachment.
Attach File Save Option : Give Notes.


Now Check in portal. you can see a upload file option. Here you can select the file which you want to upload.

After that you have to submit the form to upload the file.


Now to see your uploaded Attachments:

Step 3: Open CRM and add Notes/Timeline section in your CRM form from which you want to see Notes from portal.

Step 4: Make Notes the default tab.

Now check in Portal. you are able to see your uploaded documents.

To download the Notes : 
 Just Click on your uploaded document. If you got Mess like Not found as show in below Snapshot
 then follow the below step otherwise you can skip this.

Step 5: Now open Entity Form record from which you want to download the documents from portal.

Step 6: Now scroll down Entity Form and make sure Entity Permission checkbox should be checked.

Step 7: Now go to Portal Entity Permission.

Step 8: Create a new Entity Permission.
Name: Give the name of permission.
Entity Name: Select Note entity.
Website: Select website on which you are working.
Scope:  Select Global Scope and checked all check-boxes.


Step 9: Scroll Down the Record and reach Web Role Subgrid.

Step 10: Add web role here for this entity permission. The Web Role associated to the Portal Contact should also be associated with this Entity Permission. here i am admin that's why i added admin role.

Now you are able to download the Notes.
But with this 2nd Method, you are not able to Edit and Delete the Notes.


So that is based upon your requirement, you can use any method (method 1 or method 2).


Most Important Difference between method 1 and Method 2 is :
In method 1: you can upload document without submit entity form and you can Delete and Edit the notes also. but you can not upload multiple documents in one time. This method can be used when we update the records.

In method 2: To upload document, you have to submit Entity Form from portal but in this method you can upload multiple files. This method can be used when we Create/Update the records.



Issue Come: If you want to upload the document from CRM side and get visible in Portal side then during the upload document from CRM, add text *WEB*

D365 Portal Modify User's Profile Dropdown/Navigation Menu, Rename SignOut and Profile, add Web Page in User's Profile Dropdown/Navigation

Sometime we have a requirement like change or add one more web pages or add one extra drop-down in header's menu. To achieve this scenario, just hover the header's menu part and add pages in header's menu bar. but if you notice you are not able to modify User's Profile Dropdown/Navigation menu and you have a requirement to change it then how could we do this.

In this post i will show you, how we can modify or work with User's Profile Dropdown/Navigation menu. Here i have listed some of my requirements :-
  • Rename profile to My Profile.
  • Add one more web page in user profile drop-down.
  • Rename Sing Out to Logout.
Firstly i will show you, how we can rename profile to my profile and add one more web page in drop-down.

Step 1: Go to Portal > Web Link Sets in CRM.


Step 2: Open the record whose name is Profile Navigation(This is the record which is used for User's Profile Dropdown/Navigation ).

Step 3: Scroll down the record and reach Links Sub-grid. (The records in Sub-grid is same as number of web pages in User's profile navigation ).


Now to Rename the Profile :-- 

Step 4) Open Profile record and change it's name to My Profile.


  Now check in portal. It has been successfully changed.

Now i will show, How to add one more web page in User's Profile Dropdown/Navigation, Here i am considering, you have created your web page in CRM. if you do not know about this then click Here.

Step 5)  Now in Link Sub-grid of Profile Navigation, click on + icon and create a new Web Link and fill the needful information. And also scroll down the record and give display order.


Name: Give the Name what you want. (it will be visible in profile navigation)
Page: Now add web page in lookup field which you want to bind with this.
Display Order: Used to make sequences in web pages.

Now check in Portal :
Now i will show you, How to Rename Sign-out :-

Step 1: Go to Portal > Content Snippet.


Step 2: Create a new Content Snippet.

Name: it would be links/logout
Website: select website for which you are working.
Value: Give value which you want to show. Here i am giving Log Out.

Step 3: Now save the records and check in portal. (Before check in portal, Clear the cache in portal, do not know about cache in portal then click Here)

Get more than 10 records in Odata Query in D365 portal / ADX Studio portal.

When we fetch the data using Odata Query, we get only 10 records but if we need more than 10 records then how could we do this. Here i will show you two methods, with the help of these methods we can retrieve more than 10 records.

Method 1: Increase the page size.

Step 1: In this method, we don't need to change the code. Just go to Entity List from where you are retrieve the data. Open Entity List and increase the Page size number. Here i am changing it from 10 to 100. By default it;s size is 10.

Now check the data, you will get 100 records.

Method 2: Using Recursive.

Step 1: With the help of recursion, we can retrieve more than 10 records. Copy the below code and paste in your code editor.

 var  result ;
 function getData(){
    $.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "~/_odata/Cases" ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {              
         result =   data.value ;
url = data["odata.nextLink"];
if(url)
   getMoreData(url);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
}

  function getMoreData(url){
    $.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: url ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {            
          result = result.concat(data.value);
  url = data["odata.nextLink"];
  if(url)
   getMoreData(url);

},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
  }
 


Now check the result, you will get all the records.

Use Jquery DataTable to show the list of data in D365 Portal / ADX Studio Portal.

As we all know that, To show the list of data in portal, We used the Entity List but sometime we have a requirement to show the filtered data that's why we have to use JQuery DataTable to show the list of data. In this post i will show you, How we can fetch the data from CRM and show this data as a table format in our portal.

PreRequisite:  You should know :
1)  How to use OData query in portal. if you don't know then Click Here to know that.
2)  About Web-Template. Click Here to know about that.

Step 1: Copy the below code and paste this code in your code editor and change the code as per your requirement. In this code i am fetching the Case Entity data using OData Query and bind the data in Table.

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<br>   

<body onload="showTable()">
<table id="caseTable" class="table">
   <thead>
<tr>
  <td>Title </td>
  <td>  Name  </td>
</tr>
   </thead>
</table>
</body>

<script> 
 function showTable(){ 
    // Fetch the Case Entity Data in JSon format.
    $.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "~/_odata/Cases",
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {
         result =   data.value ;
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}   
}); 

    // Now bind the JSon data in Table format
$('#caseTable').DataTable({
"aaData": result,
"columns": [                                                 
{ "data": "title" },  // Here give the column name(The data which you want to show).
{ "data": "title" }
]
});
}
  
</script>

Step 2: Now paste this code in your web template. 

Step 3: Now check your web page in your portal.



Sometime we get the error in pop-up form like "Cannot reinitialise DataTable".
To solve this error, add this code in your DataTable : "destroy": true,



When we fetch the data using Odata Query, we get only 10 records. To get more than 10 records, Click Here to know that.

Apply Custom Hyperlink on other field in Entity List in D365 Portal / ADX Studio Portal.

Hello guys....Sometimes we have a requirement to apply hyperlink on other field in Entity List or apply custom hyperlink. In this post i will explain, how we can achieve this.
If you don't know, how we can apply entity list then click Here to know that.

Follow the steps to apply hyperlink on other field in entity list.

Step 1: Copy the below code and paste it in your editor box. Now change the code as per your need.
Here i am going to apply hyperlink on Case Title field in Case Entity List.

$('.entitylist').on("loaded", function () {

//To make the field/column's value hyperlink
//$("td[data-attribute*='Field's BackEnd Name']").each(function() {

// For Example
$("td[data-attribute*='title']").each(function() {

// Get guid of record - This will give you the GUID of Current Record (Current Row).
var GUID = $(this).closest('tr').attr("data-id");

// This code will give you the current value of field which you want to make as hyperlink. WIth the help of this value we can find GUID using Web API
// var value = this.dataset.value;
// might need to change the line a bit to get the record guid


// Partial URL of webpage where you want to redirect the user.
//var pagewhereToRedirect = "Partial URL of Web Page";

// For Example
var pagewhereToRedirect = "edit-case";

// Construct the URL
var redirect = window.location.href + pagewhereToRedirect + "/?id="+ GUID;

// Make the field value Hyperlink
var text=$(this).text();
$(this).html("<a href="+redirect+">"+text+"</a>");

});
});


Step 2:  After make changes in your code. Upload this code in Web Page JS Section.

Now check the Entity List.....




If you want to open hyperlink page in another tab then add below code also :

$('.entitylist').on("loaded", function () { 
  $("a").attr("target","_blank");
});

Use Jquery DataTable to Create a custom Sub-Grid in MS Dynamic CRM.

Sometime we need to show our data in table format. We should use Jquery DataTable to show the data in sub-grid (Table) format. In this post i will explain step by step, how we can create a DataTable.

Step 1: Copy the below code and paste this code in your editor. And change the code as per your need. Here i will create a DataTable of Case Entity.

<html>
<head>
    <title>MS Dynamic CRM</title>
 
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"> </script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"> </script>
 
<script>

  var dataSet;
  var arrData = [];

$(document).ready(function() {
// Get the data in Json format, Change the URL as per your need.
  var entityName ="incident"; // This is the Entity name of Case.
var  url = window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + entityName +"s?$select=title,ticketnumber,prioritycode";  
var myData = [];
var req = new XMLHttpRequest();
req.open("GET",url, false);
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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
  myData = JSON.parse(this.response);
  dataSet=myData.value;   
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
   
  // Convert Json data into 2-d Array
   arrItems = [];   
$.each(dataSet, function (index, value) {
arrItems.push(value.title);
arrItems.push(value.ticketnumber);
   // arrItems.push(value.prioritycode); or
arrItems.push(value["prioritycode@OData.Community.Display.V1.FormattedValue"]) ; // For OptionSet value
arrData.push(arrItems); // Push The Values Inside the Array to Create 2-D Array
arrItems = [];
});
   
table(); // Call a table function to create table.
});

function table() {
$('#customdatatable').DataTable( {
        data: arrData,
        columns: [
            { title: "Title" },  // Change the column name as per your need.
{ title: "Ticket Number" },
{ title: "Priority" }         
        ]
    } );
}

</script>
</head>

<body style="word-wrap: break-word;">
 
<table id="customdatatable" class="display" width="100%"></table>

</body>
</html>

Step 2: After make changes in code, Create a new HTML Web-resource and Upload the code in this web-resource and check the table.



How to get GUID of selected records from home page entity view using Java-Script in MS Dynamic CRM.

Sometime we need to apply some operations on selected records in home page entity view by clicking on custom button. To apply operations, firstly we need to get GUID of these selected records then we can apply any kind of operations of these records. In this post, i will show you how to retrieve GUID of selected records.


Step 1: Copy the below code and paste it in your Java-Script file .

function selectedRecord(selectedIds) {
    if (selectedIds != null && selectedIds != "") {
        var strIds = selectedIds.toString();
        var arrIds = strIds.split(",");
        for (var i = 0; i < arrIds.length; i++) {          
alert(arrIds[i]);
// do your operations here
        }       
    }
    else {
        alert("No records selected!");
    }
}

Step 2: Now Add custom button in your home page using Ribbon Workbench Tool.


Step 3: Now Add New Command for this button. And after that, add new actions for this command.



Step 4: In this Action, add lib. and give the Function Name.Here our function is selectedRecord. Now click on parameter to get selected records GUID.

Step 5: Click on Add to add a new parameter. And then select the CRM Parameter option.


Step 6: Value of parameter is SelectedControlSelectedItemsIds as show in below Snapshot.

Step 7: Now select your command in command bar and then publish your solution.



Now do the testing. Select the records and then click on button. you will get GUID of these selected records.