Wednesday, November 07, 2007

Close Selected Letters Microsoft CRM 3.0

one thing that ask me when i was develomp in CRM is close the selected letters i selected in grid, to do this you have to add in isv.config.xml file and add this line

<entity name="activitypointer">
<grid>
<menubar>
<buttons>
<button title="Close Letter" javascript="doIsvAction('crmGrid', 'closeLetter.htm', 0, '');" winmode="1" winparams="" passparams="1" icon="/_imgs/ico/16_L_remove.gif" tooltip="Close Selected Letters">
</buttons>
</menubar>
</grid>
</entity>

After this you can create a html page that call the following javascript and will close the select letters you select in the grid.



<script>
var selected = true;
var unselected = true;
function ShowGuids()
{
if(confirm('Deseja apagar a(s) Carta(s) selecionada(s)?')== true)
{
if(window.opener == null)
{
return;
}


var content = "<table>";
var allRows = window.opener.document.getElementsByTagName("tr");

for(i=0; i<allRows.length; i++)
{

if (allRows[i].otype=="4207" && allRows[i].className == "gridSelectOn")
{

var activityid = allRows[i].oid;

var serverUrl = "/mscrmservices/2006";

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

//alert(serverUrl+ "/crmservice.asmx");

xmlhttp.open("POST", serverUrl + "/crmservice.asmx", false);

xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")

xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/Execute")

xmlhttp.send("<?xml version='1.0' encoding='utf-8'?>"+"\n\n"+"<soap:Envelope"+

' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+

' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+

' xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+

' <soap:Body>' +

' <Request xsi:type="SetStateLetterRequest"'+

' xmlns="http://schemas.microsoft.com/crm/2006/WebServices"> '+

' <EntityId>' + activityid + '</EntityId>'+

' <LetterState>Completed</LetterState>'+

' <LetterStatus>4</LetterStatus>'+

' </Request>'+

' </soap:Body>'+

' </soap:Envelope>')

var result = xmlhttp.responseXML.xml;
/*
if (result.indexOf('faultcode') < 0) {

window.open('/CRMReports/viewer/drillopen.aspx?ID=' + activityid + '&OTC=4201');

} else {

alert(result);

}
*/


content += "<tr>";
content += "<td>" + allRows[i].oid + "</td>";
content += "<td>" + allRows[i].otype + "</td>";
content += allRows[i].innerHTML;
content += "</tr>";
}
}
}
else
{
window.close()
}


content += "</table>";
content;

document.getElementById("area").innerHTML = content;
window.opener.location.reload();
window.close()
}

function ShowSelected()
{
selected = !selected;
ShowGuids();
}

function ShowUnselected()
{
unselected = !unselected;
ShowGuids();
}

</script>
Post a Comment