Friday, July 24, 2015

Dynamics CRM 2015 / 2013 /2011 – Multi Select Option List / Pick list / Dropdown

Dynamics CRM 2015 / 2013 /2011 – Multi Select Option List / Pick list / Dropdown



1)     Create a HTML Web Resource MultiSelectPicklist.html


<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="sa_jQuery"></script>
<script type="text/javascript" src="sa_JSON"></script>
<script src="ClientGlobalContext.js.aspx"></script>
 
<script type="text/javascript">
 
var PicklistFieldName;
var TextAttributefield;
 
document.onreadystatechange = function () {
if (document.readyState == "complete") {
getDataParam();
}
}
 
function getDataParam() {
//Get the any query string parameters and load
 
var vals = new Array();
if (location.search != "") {
vals = location.search.substr(1).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}
//look for the parameter named 'data'
var found = false;
for (var i in vals) {
if (vals[i][0].toLowerCase() == "data") {
parseDataValue(vals[i][1]);
found = true;
break;
}
}
if (!found) {
noParams();
}
}
else {
noParams();
}
}
 
function setText(element, text) {
if (typeof element.innerText != "undefined") {
element.innerText = text;
}
else {
element.textContent = text;
}
}
 
function parseDataValue(datavalue) {
PicklistFieldName = '';
TextAttributefield = '';
if (datavalue != "") {
vals = decodeURIComponent(datavalue).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}
 
var temp = vals[i][0].split(';');
 
if (temp.length == 2) {
PicklistFieldName = temp[0];
TextAttributefield = temp[1];
}
else {
noParams();
}
}
else {
noParams();
}
}
 
function noParams() {
var message = document.createElement("p");
setText(message, "No data parameter was passed to this page");
 
document.body.appendChild(message);
}
 
function CreateMultiSelectPicklist() {
if (PicklistFieldName != '' && TextAttributefield != '') {
var dropdownOptions = parent.Xrm.Page.getAttribute(PicklistFieldName).getOptions();
var selectedValue = parent.Xrm.Page.getAttribute(TextAttributefield).getValue();
 
parent.Xrm.Page.getControl(PicklistFieldName).setVisible(false);
parent.Xrm.Page.getControl(TextAttributefield).setDisabled(true);
 
// Create Multi Select Picklist with values from input picklist.
$(dropdownOptions).each(function (i, e) {
var rText = $(this)[0].text;
var rvalue = $(this)[0].value;
var isChecked = false;
if (rText != '') {
 
if (selectedValue != null && selectedValue.indexOf(rText) != -1)
isChecked = true;
 
var checkbox = " input type='checkbox'  name='r'/>" + rText + ""
$(checkbox)
.attr("value", rvalue)
.attr("checked", isChecked)
.attr("id", "id" + rvalue)
.attr("style", 'border:none; width:25px; align:left;')
.click(function () {
 
//To Set Picklist Select Text
var selectedYear = parent.Xrm.Page.getAttribute(TextAttributefield).getValue();
if (this.checked) {
if (selectedYear == null)
selectedYear = rText + ";";
else
selectedYear = selectedYear + rText + ";"
}
else {
var tempSelectedtext = rText + ";";
if (selectedYear.indexOf(tempSelectedtext) != -1)
selectedYear = selectedYear.replace(tempSelectedtext, "");
else
selectedYear = selectedYear.replace(rText, "");
}
 
parent.Xrm.Page.getAttribute(TextAttributefield).setValue(selectedYear);
 
})
.appendTo(checkboxList);
}
});
}
}
 
</script>
 
<meta charset="utf-8">
</head>
<body style="border: 1px solid rgb(102, 153, 204); overflow-y: auto; background-color: rgb(255, 255, 255);" onload="CreateMultiSelectPicklist()">
<div id="checkboxList">
</div>
</body>
</html>
 

Monday, February 24, 2014

Hide Unwanted Activities from Activities view Dropdown in MSCRM2011/ MSCRM2013 /MSCRM2015 using javascript

Create a JavaScript web resource with following functions.
 
function AttachHideEvent()
{
    document.getElementById("crmGrid_SavedNewQuerySelector").setAttribute('onclick','HideItems();');
 
    $( "#crmGrid_SavedNewQuerySelector" ).mouseout(function() { HideItems(); });
 
}
 
function HideItems()
{
    if(document.getElementById("ViewSelector_fax") !=null)
    {
        //fax
        document.getElementById("ViewSelector_fax").style.visibility = "hidden";
        document.getElementById("ViewSelector_fax").style.height="0px";
        document.getElementById("ViewSelector_fax").style.float="left";
        //Letter
        document.getElementById("ViewSelector_letter").style.visibility = "hidden";
        document.getElementById("ViewSelector_letter").style.height="0px";
        document.getElementById("ViewSelector_letter").style.float="left";
    }
}
 
 
Then add a enable rule to first button on activities homepage ribbon and call this function with default value = true/ function name= AttachHideEvent/ webresource=web resource created.
 
In 2nd function add activities you want to hide from dropdown.
 

Friday, October 2, 2009

Connect to CRM 1.2

#region "Connect to CRM 1.2"
///
/// This fucntion will connect to CRM 1.2
///

/// After sucessfully connection it will return CRM 1.2 user authentication
private Microsoft.CRM.Proxy.CUserAuth connectToCRM()
{
// BizUser proxy object
Microsoft.CRM.Proxy.BizUser bizUser = new Microsoft.CRM.Proxy.BizUser();
bizUser.Credentials = new System.Net.NetworkCredential(userName, password, domain);
bizUser.Url = strDir + "BizUser.srf";

try
{
userAuth = bizUser.WhoAmI();
//MessageBox.Show("Sucessfully connected to CRM 1.2");
}
catch (System.Web.Services.Protocols.SoapException ex)
{
MessageBox.Show("Unable to connect to CRM 1.2, Please check CRM 1.2 details.", ex.Message.ToString());
return null;
}

return userAuth;
}

#endregion

Download file form web / IE without Save/Open dialog box

string url = "http://"; // Download File path
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.Credentials = new System.Net.NetworkCredential("User Name", "Password", "Domain");

string sFile ="C:\\"; //Path to save file

myWebClient.DownloadFile(url, sFile);

Update / Set CRM Opportunity State/ Status

public bool UpdateOpportunityState(Guid activityid, string astatuscode, string astatecode)
{

CrmService Crm4_service = connect();
try
{
if (astatecode == "Open")
{
SetStateOpportunityRequest state = new SetStateOpportunityRequest();

if (astatuscode == "1")
{
return true;
}
else if (astatuscode == "2")
{
state.OpportunityState = OpportunityState.Open;
state.OpportunityStatus = 2;/// Convert.ToInt32();
}

state.EntityId = activityid;
SetStateOpportunityResponse stateSet = (SetStateOpportunityResponse)Crm4_service.Execute(state);

return true;
}



opportunity src_opp = (opportunity)Crm4_service.Retrieve(EntityName.opportunity.ToString(), activityid, new AllColumns()); // = OpportunityState.Lost;


opportunityclose opp_close = new opportunityclose();
opp_close.actualrevenue = src_opp.actualvalue;
opp_close.opportunityid = new Lookup();
opp_close.opportunityid.Value = src_opp.opportunityid.Value;
opp_close.actualend = src_opp.actualclosedate;
opp_close.statuscode = src_opp.statuscode;
if (astatuscode == "3")
{
// this Opportunity was won
WinOpportunityRequest opp_won = new WinOpportunityRequest();
opp_won.OpportunityClose = opp_close;
opp_won.Status = 3;// src_opp.statuscode.Value;
Crm4_service.Execute(opp_won);
return true;
}
else
{
// this Opportunity was lost
LoseOpportunityRequest opp_lost = new LoseOpportunityRequest();
opp_lost.OpportunityClose = opp_close;
if (astatuscode == "4")
{
opp_lost.Status = 4;// src_opp.statuscode.Value;
}
else
{
opp_lost.Status = 5;// src_opp.statuscode.Value;

}
Crm4_service.Execute(opp_lost);
return true;
}

}
catch (System.Web.Services.Protocols.SoapException ex)
{
return false;
}

return true;


}

Update / Set CRM Invoice Status/ state

internal bool updateInvioceState(Guid InvioceId, string statusCode, string stateCode)
{
try
{
CrmService Crm4_service = connect();
SetStateInvoiceRequest state = new SetStateInvoiceRequest();

if (stateCode == "Active")
{
state.InvoiceState = InvoiceState.Active;
}
else if (stateCode == "Canceled")
{
state.InvoiceState = InvoiceState.Canceled;
}
else if (stateCode == "Closed")
{
state.InvoiceState = InvoiceState.Closed;
}
else if (stateCode == "Paid")
{
state.InvoiceState = InvoiceState.Paid;
}

state.InvoiceStatus = Convert.ToInt32(statusCode);
state.EntityId = InvioceId;
SetStateInvoiceResponse stateSet = (SetStateInvoiceResponse)Crm4_service.Execute(state);

}
catch (System.Web.Services.Protocols.SoapException ex)
{
return false;
}
return true;
}