Answered by:
Create a Closed Activity Notification Field

Question
-
We are using CRM 2011 on site.
Is it possible to make a field on my case entity(re-named it Client Request) that would notify a user when closed activity exists?
If so, can anyone help me to create a field like this? I am familiar with how to create custom fields and how to add them to my form. What I don't know how to do is create java script or maybe use some other way to fill that field with a yes or no or a checkbox with a check or no check when closed activity is present for the case that the user is viewing.
Wednesday, January 23, 2013 8:53 PM
Answers
-
Yes,You can also do it in this way . Initially create a custom field with data type of option-set then set items in it as "closed" and "opened" .Later on using the workflow when ever the record is closed then set the value of the custom field as closed and then send an email to the user using the workflow that your case activity has been completed .This will be more easier to the user to have a detail status of his case.
- Proposed as answer by meenakshi Patnala Thursday, January 24, 2013 5:13 AM
- Marked as answer by JLattimerMVP, Moderator Saturday, February 16, 2013 10:08 PM
Thursday, January 24, 2013 5:13 AM -
Try executing this code in your case form OnLoad function:
function GetCompletedActivities() { //set the path to the odata rest service //this can be hardcoded using the Organization Rest Service URL under Customizations->Developer Resources var odataPath = "https://" + window.location.host + "/XRMServices/2011/OrganizationData.svc"; //get the parent account lookup var caseid = Xrm.Page.data.entity.getId(); //set up the odata query var retrieveReq = new XMLHttpRequest(); var odataQuery = odataPath + "/ActivityPointerSet?$select=ActivityId,StateCode&$filter=StateCode/Value eq 1 and RegardingObjectId eq guid'" + caseid + "'"; retrieveReq.open("GET", odataQuery, false); //make sure we get json back retrieveReq.setRequestHeader("Accept", "application/json"); retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8"); //request/response will execute asynchronously, so we need a callback function retrieveReq.onreadystatechange = function () { HasClosedActivity(this); }; //send the request retrieveReq.send(); } //callback function to parse the response and react accordingly function HasClosedActivity(retrieveReq) { //4 means a complete response if (retrieveReq.readyState == 4) { //parse response to json var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d; if(retrieved.length>0) { Xrm.Page.getAttribute("YOUR_CHECKBOX_NAME").setValue(true); } }; }
It uses OData to retrieve all completed activities that are linked to the case. Then it passes the array of retrieved records to a callback function. The callback function checks the length of the array, and if it is > 0, then it checks a checkbox on the form. You could just as easily pop an alert message, put text in a field, disable/enable a field, etc.
I haven't actually checked that code completely, but I think it's at least pretty close.
- Proposed as answer by Lucas Alexander Thursday, January 24, 2013 5:21 AM
- Marked as answer by JLattimerMVP, Moderator Saturday, February 16, 2013 10:08 PM
Thursday, January 24, 2013 5:18 AM
All replies
-
Yeah, you could add a field with two values and then build workflows for every activity:
1) Check if the activity status is 'closed'
2) Update the field of regarding-record of the case to true
Wednesday, January 23, 2013 9:36 PM -
Yes,You can also do it in this way . Initially create a custom field with data type of option-set then set items in it as "closed" and "opened" .Later on using the workflow when ever the record is closed then set the value of the custom field as closed and then send an email to the user using the workflow that your case activity has been completed .This will be more easier to the user to have a detail status of his case.
- Proposed as answer by meenakshi Patnala Thursday, January 24, 2013 5:13 AM
- Marked as answer by JLattimerMVP, Moderator Saturday, February 16, 2013 10:08 PM
Thursday, January 24, 2013 5:13 AM -
Try executing this code in your case form OnLoad function:
function GetCompletedActivities() { //set the path to the odata rest service //this can be hardcoded using the Organization Rest Service URL under Customizations->Developer Resources var odataPath = "https://" + window.location.host + "/XRMServices/2011/OrganizationData.svc"; //get the parent account lookup var caseid = Xrm.Page.data.entity.getId(); //set up the odata query var retrieveReq = new XMLHttpRequest(); var odataQuery = odataPath + "/ActivityPointerSet?$select=ActivityId,StateCode&$filter=StateCode/Value eq 1 and RegardingObjectId eq guid'" + caseid + "'"; retrieveReq.open("GET", odataQuery, false); //make sure we get json back retrieveReq.setRequestHeader("Accept", "application/json"); retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8"); //request/response will execute asynchronously, so we need a callback function retrieveReq.onreadystatechange = function () { HasClosedActivity(this); }; //send the request retrieveReq.send(); } //callback function to parse the response and react accordingly function HasClosedActivity(retrieveReq) { //4 means a complete response if (retrieveReq.readyState == 4) { //parse response to json var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d; if(retrieved.length>0) { Xrm.Page.getAttribute("YOUR_CHECKBOX_NAME").setValue(true); } }; }
It uses OData to retrieve all completed activities that are linked to the case. Then it passes the array of retrieved records to a callback function. The callback function checks the length of the array, and if it is > 0, then it checks a checkbox on the form. You could just as easily pop an alert message, put text in a field, disable/enable a field, etc.
I haven't actually checked that code completely, but I think it's at least pretty close.
- Proposed as answer by Lucas Alexander Thursday, January 24, 2013 5:21 AM
- Marked as answer by JLattimerMVP, Moderator Saturday, February 16, 2013 10:08 PM
Thursday, January 24, 2013 5:18 AM