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;
}

Tuesday, September 22, 2009

Update/ Set AccountStateInfo in CRM 4.0 / 3.0

private bool UpdateAccountState(Guid accid, string astatuscode, string astatecode)
{
bool checkflag = false;
try
{
CrmService Crm4_service = connect();
// Create the request object.
SetStateAccountRequest state = new SetStateAccountRequest();

// Set the properties of the request object.
if (astatecode == "Inactive")
{
state.AccountState = AccountState.Inactive;
}
if (astatecode == "Active")
{
state.AccountState = AccountState.Active;
}
state.AccountStatus = Convert.ToInt32(astatuscode);

// EntityId is the GUID of the account whose state is being changed.
state.EntityId = accid;

// Execute the request.
SetStateAccountResponse stateSet = (SetStateAccountResponse)Crm4_service.Execute(state);
checkflag = true;
}
catch
{
return checkflag;
}
return checkflag;
}

Saturday, July 18, 2009

Send Email Activity using template from CRM 3.0 / 4.0 using C#

private void SendEmailFromTemplate()
{
CrmService service = connect();
// Create the 'From:' activity party for the email
activityparty fromParty = new activityparty();
fromParty.partyid = new Lookup();
fromParty.partyid.type = EntityName.systemuser.ToString();
fromParty.partyid.Value = new Guid("4D52A946-AE37-DE11-B372-000C29DF4A76");

// Create the 'To:' activity party for the email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.account.ToString();
toParty.partyid.Value = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");

// Create an email message.
email email = new email();

// Set email properties
email.to = new activityparty[] { toParty };
email.from = new activityparty[] { fromParty };
email.subject = "SDK Sample email";
email.description = "SDK Sample for SendEmailFromTemplate Message.";

CrmBoolean direction = new CrmBoolean();
direction.Value = true;
email.directioncode = direction;

TargetSendFromTemplateEmail emailTemplateTarget = new TargetSendFromTemplateEmail();
emailTemplateTarget.Email = email;

SendEmailFromTemplateRequest emailRequest = new SendEmailFromTemplateRequest();
emailRequest.Target = emailTemplateTarget;

// The regarding Id is requried and must be of the same type as the Email Template
emailRequest.RegardingId = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");
emailRequest.RegardingType = EntityName.account.ToString();

// Use a built-in email template of type "contact".
emailRequest.TemplateId = new Guid("B6C38BB9-2423-471D-8B38-E3B99ED80E7A");

SendEmailFromTemplateResponse emailResponse = (SendEmailFromTemplateResponse)service.Execute(emailRequest);
}