How to do it...

  1. Navigate to Settings | Solutions | Packt.
  2. Click on Web Resources and click on New, enter contact.js next to the name, select Script (JScript) from Type, and click on Text Editor.
  1. Copy and insert the following code and click on OK:
var packtNs = packtNs || {}; 
packtNs.contact = packtNs.contact || {};
packtNs.contact.checkActiveTasksAssignedToMe = function()
{
var uniqueNotificationId = "OutstandingTasks";
Xrm.Page.ui.clearFormNotification(uniqueNotificationId);
var contactId =
Xrm.Page.data.entity.getId().replace(/[{}]/g,"");
var currentUserId =
Xrm.Page.context.getUserId().replace(/[{}]/g,"");
var req = new XMLHttpRequest();
var requestUrl = Xrm.Page.context.getClientUrl() +
"/api/data/v8.2/tasks?$filter=_regardingobjectid_value
eq " + contactId + " and _ownerid_value eq " +
currentUserId + " and statecode eq 0";
req.open("GET", requestUrl, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-
annotations="OData.Community.Display.V1.FormattedValue"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
if(results.value.length > 0){
Xrm.Page.ui.setFormNotification("You have
outstanding tasks assigned to you.", "WARNING",
uniqueNotificationId)
}
}
else {
//.. handle error
}
}
};
req.send();
}
  1. Click on Save, and then close your window.
  2. Back in your Packt solution, navigate to Entities | Contact | Forms and double-click on the Main form.
  3. Click on Form Properties and, under Form Libraries, click on the add symbol (+).
  4. Select your JavaScript library, packt_contact.js, from the list (you can use the search functionality to filter the values). Click on Add and then click on OK.
  5. Under Event Handlers, verify that Control is set to Form and Event is set to OnLoad, then click on +.
  6. Ensure that packt_contact.js is selected in the Library dropdown, and then enter packtNs.contact.checkActiveTasksAssignedToMe in the Function field.
  7. Click on Save and Close, followed by Publish All Customizations in your solution window.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.195.34