Showing posts with label CRM. Show all posts
Showing posts with label CRM. Show all posts

Thursday, December 2, 2010

Simple CRM Priority Dropdown to change Due Date

This next situation I ran into, called for a Due Date field and a Ticket Priority Pick List, they requested that when a technician comes into the ticket and changes the priority status it will automatically update the Due Date.  The Due Date is auto-populated with a Normal priority, so the Due Date will be 7 Days after Todays date, This will be pushed forward or back depending on the priority status selected.

For Example If I selected :
High priority will change the Due Date to Todays Date.
Normal priority will push the Due Date back 7 days from Today.
Low priority will push the Due Date back 14 days from Today.
Standby priority will push the Due Date back 30 days from Today.

So, How'd I do this?
I created two fields in CRM 4.0
One is called datedue, which is a basic date field
The second is a Priority picklist with the following types:
Low
Medium
High
Standby
  • Open up the Main Form
  • Change properties on the Priority Field
  • Click Events Tab
  • Edit onChange
  • Check that the Event is enabled
  • Paste the following code:
var PRIORITY_HIGH="High";
var PRIORITY_NORMAL="Medium";
var PRIORITY_LOW="Low";
var PRIORITY_STANDBY="Standby";
var DUE;
var TODAY;
{
TODAY = new Date();
// If Due Date is null, set it to today's date.
DUE = crmForm.all.new_datedue.DataValue;
if (DUE == null)
{
DUE = new Date();
}
// Set the due date based on the value of the Priority field.
switch (crmForm.new_priority.SelectedText) {
case PRIORITY_HIGH:
DUE = TODAY;
break;
case PRIORITY_LOW:
DUE = TODAY.setDate( TODAY.getDate() + 14);
break;
case PRIORITY_NORMAL:
DUE = TODAY.setDate( TODAY.getDate() + 7);
break;
case PRIORITY_STANDBY:
DUE = TODAY.setDate( TODAY.getDate() + 30);
break;
}
crmForm.all.new_datedue.DataValue = DUE;
}
  •  Save and Close, Test Changes, Publish the Entity

Adding a CRM 4.0 Related Entity to the Main Form using IFRAME

First create your two entities and relate them together.

  • On the main form, create an iframe section
  • Create a new IFRAME, place it in the section





















URL: about:blank
  • Open the Form Properties
  • Edit Onload
  • Check Event is enabled
  • Paste the following code
var navId = "nav_new_new_assets_new_assetitem";
if(document.getElementById(navId) != null)
{
var tmp = document.getElementById(navId).onclick.toString();
tmp = tmp.substring(tmp.indexOf("'")+1, tmp.indexOf(";"));
var loadArea = tmp.substring(0, tmp.indexOf("'"));
var roleOrd = (tmp.indexOf("roleOrd") == -1) ? -1 : tmp.substring( tmp.indexOf("roleOrd"), tmp.lastIndexOf("'")).replace("\x3d", "=");
crmForm.all.IFRAME_Items.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + "&" + roleOrd;
}
function GetFrameSrc(tabSet)
{
if (crmForm.ObjectId != null)
{
var id = crmForm.ObjectId;
var type = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
var path = document.location.pathname.substring(0, document.location.pathname.indexOf("edit.aspx")) + "areas.aspx?";
return (path + "oId=" + id + "&oType=" + type + "&security=" + security + "&tabSet=" + tabSet);
}
else
{
return "about:blank";
}
}
  • Now there are two things we need to edit here (items in bold). 
  • First one is var navId=
    • This needs to be the related entity, but we want the navId, not the URL.
    •  Easy way to find this ID, is to use IE Developer Tools.
      • Open your main form
      • Click Tool > Developer Tools
      • Within Developer Tools, Click the ARROW (Select Element by Click)
      • Now go back to your main form and click the related entity under details
      • A New window will appear in Developer Tools, It should have highlighted the CRM Nav Subarea.
      • Locate the ID=

  • Next Change is the crmForm.all.IFRAME_Items.src
    • Make sure to use your proper iframe ID (Iframe_Items)
  • That should be it, Save and Close.
  • Publish your entity and make sure the related entity is displaying properly