Wednesday, January 20, 2010

Making Description Field Required in Close Opportunity Dialog

This is unsupported customization, so be careful.

Open folder with your CRM website. Open SFA\opps subcatalog.

Open dlg_closeopp.aspx file using notepad and find there following function:

function applychanges()
{
var retval = "";


if (actualend.DataValue == null)
{
alert( LOCID_CLOSE_DATE_NOT_SUPPLIED );
actualend.SetFocus();
return;
}

if ((actualrevenue.DataValue == null) && radWon.checked)
{
alert( LOCID_ACT_REVENUE_NOT_SUPPLIED );
actualrevenue.focus();
return;
}


var xml = "<opportunityclose>";
xml += actualrevenue.DataXml;
xml += "<activityid><%= SequentialGuid.CreateGuid().ToString("B", CultureInfo.InvariantCulture).ToUpper(CultureInfo.InvariantCulture) %></activityid>";
xml += "<opportunityid>" + _iId + "</opportunityid>";
xml += description.DataXml;

xml += actualend.DataXml;
xml += "<subject>" + CrmEncodeDecode.CrmXmlEncode(_subject) + "</subject>";
if (radLost.checked)
{
with(crmLookup)
{
if(!IsNull(DataValue))
{
xml += "<competitorid>" + DataValue[0].id + "</competitorid>";
}
}
}
xml += "</opportunityclose>";

var oReturn = new Object();
var wonState = 1;
var lostState = 2;

oReturn.State = ((radWon.checked) ? wonState : lostState);
oReturn.StatusCode = ((radWon.checked) ? selWinStatus.DataValue : selLoseStatus.DataValue);
oReturn.ActivityXml = xml;

window.returnValue = oReturn;
window.close();

}


and modify it to:

function applychanges()
{
var retval = "";


if (actualend.DataValue == null)
{
alert( LOCID_CLOSE_DATE_NOT_SUPPLIED );
actualend.SetFocus();
return;
}

if ((actualrevenue.DataValue == null) && radWon.checked)
{
alert( LOCID_ACT_REVENUE_NOT_SUPPLIED );
actualrevenue.focus();
return;
}

if (description.value.replace(/^\s+|\s+$/, '') == '')
{
alert('Input Description!');
description.focus();
return;
}

var xml = "<opportunityclose>";
xml += actualrevenue.DataXml;
xml += "<activityid><%= SequentialGuid.CreateGuid().ToString("B", CultureInfo.InvariantCulture).ToUpper(CultureInfo.InvariantCulture) %></activityid>";
xml += "<opportunityid>" + _iId + "</opportunityid>";
xml += description.DataXml;

xml += actualend.DataXml;
xml += "<subject>" + CrmEncodeDecode.CrmXmlEncode(_subject) + "</subject>";
if (radLost.checked)
{
with(crmLookup)
{
if(!IsNull(DataValue))
{
xml += "<competitorid>" + DataValue[0].id + "</competitorid>";
}
}
}
xml += "</opportunityclose>";

var oReturn = new Object();
var wonState = 1;
var lostState = 2;

oReturn.State = ((radWon.checked) ? wonState : lostState);
oReturn.StatusCode = ((radWon.checked) ? selWinStatus.DataValue : selLoseStatus.DataValue);
oReturn.ActivityXml = xml;

window.returnValue = oReturn;
window.close();

}


Demonstration: