Tag Cloud

CRM 2011 (161) CRM 4.0 (144) C# (116) JScript (109) Plugin (92) Registry (90) Techpedia (77) PyS60 (68) WScript (43) Plugin Message (31) Exploit (27) ShellCode (26) FAQ (22) JavaScript (21) Killer Codes (21) Hax (18) VB 6.0 (17) Commands (16) VBScript (16) Quotes (15) Turbo C++ (13) WMI (13) Security (11) 1337 (10) Tutorials (10) Asp.Net (9) Safe Boot (9) Python (8) Interview Questions (6) video (6) Ajax (5) VC++ (5) WebService (5) Workflow (5) Bat (4) Dorks (4) Sql Server (4) Aptitude (3) Picklist (3) Tweak (3) WCF (3) regex (3) Config (2) LINQ (2) PHP (2) Shell (2) Silverlight (2) TSql (2) flowchart (2) serialize (2) ASHX (1) CRM 4.0 Videos (1) Debug (1) FetchXml (1) GAC (1) General (1) Generics (1) HttpWebRequest (1) InputParameters (1) Lookup (1) Offline Plug-ins (1) OutputParameters (1) Plug-in Constructor (1) Protocol (1) RIA (1) Sharepoint (1) Walkthrough (1) Web.config (1) design patterns (1) generic (1) iframe (1) secure config (1) unsecure config (1) url (1)

Pages

Thursday, November 08, 2012

CRM 4.0 PLuGIN: sample plugin with pre & post Images

p u b l i c v o i d E x e c u t e ( I P l u g i n E x e c u t i o n C o n t e x t c o n t e x t )
{
s t r i n g m _ O p p o r t u n i t y N ame = s t r i n g . E mp t y ;
s t r i n g m _ O p p o r t u n i t y I d = s t r i n g . E mp t y ;
i f ( c o n t e x t . M e s s a g e N ame . E q u a l s ( " C r e a t e " ) )
{
/ / E n t i t y c r e a t i o n . D y n am i c E n t i t y p o s t E n t i t y ;
i f ( c o n t e x t . P o s t E n t i t y I ma g e s . C o n t a i n s ( " T a r g e t " ) )
{
p o s t E n t i t y = ( ( D y n am i c E n t i t y ) c o n t e x t . P o s t E n t i t y I ma g e s [ " T a r g e t " ] ) ;
i f ( p o s t E n t i t y . P r o p e r t i e s . C o n t a i n s ( " o p p o r t u n i t y i d " ) )
{
K e y o p p o r t u n i t y I d = ( K e y ) p o s t E n t i t y . P r o p e r t i e s [ " o p p o r t u n i t y i d " ] ;
i f ( o p p o r t u n i t y I d ! = n u l l ) { m _ O p p o r t u n i t y I d = o p p o r t u n i t y I d . V a l u e . T o S t r i n g ( ) ;
}
}
i f ( p o s t E n t i t y . P r o p e r t i e s . C o n t a i n s ( " n ame " ) )
{
m _ O p p o r t u n i t y N ame = p o s t E n t i t y . P r o p e r t i e s [ " n ame " ] . T o S t r i n g ( ) ;
}
}
}
e l s e i f ( c o n t e x t . M e s s a g e N ame . E q u a l s ( " U p d a t e " ) )
{
/ / E n t i t y u p d a t e . D y n am i c E n t i t y p r e t E n t i t y ;
D y n am i c E n t i t y p o s t E n t i t y ;
i f ( c o n t e x t . P r e E n t i t y I ma g e s . C o n t a i n s ( " T a r g e t " ) )
{
p r e t E n t i t y = ( ( D y n am i c E n t i t y ) c o n t e x t . P r e E n t i t y I ma g e s [ " T a r g e t " ] ) ;
}
i f ( c o n t e x t . P o s t E n t i t y I ma g e s . C o n t a i n s ( " T a r g e t " ) )
{
p o s t E n t i t y = ( ( D y n am i c E n t i t y ) c o n t e x t . P o s t E n t i t y I ma g e s [ " T a r g e t " ] ) ;
}
i f ( p o s t E n t i t y . P r o p e r t i e s . C o n t a i n s ( " o p p o r t u n i t y i d " ) )
{ K e y o p p o r t u n i t y I d = ( K e y ) p o s t E n t i t y . P r o p e r t i e s [ " o p p o r t u n i t y i d " ] ;
i f ( o p p o r t u n i t y I d ! = n u l l ) { m _ O p p o r t u n i t y I d = o p p o r t u n i t y I d . V a l u e . T o S t r i n g ( ) ;
}
}
i f ( p o s t E n t i t y . P r o p e r t i e s . C o n t a i n s ( " n ame " ) )
{
m _ O p p o r t u n i t y N ame = p o s t E n t i t y . P r o p e r t i e s [ " n ame " ] . T o S t r i n g ( ) ;
}
}
}

Monday, November 05, 2012

Add Button in CRM Form

 
/* Jscript: Add button in CRM */


function ConvertToButton(fieldname, buttontext, buttonwidth,clickevent, title)

{

//check if object exists; else return
if (document.getElementById(fieldname) == null)
{
return;
}


functiontocall=clickevent;
crmForm.all[fieldname].DataValue = buttontext;
crmForm.all[fieldname].readOnly = true;
crmForm.all[fieldname].style.borderRight="#3366cc 1px solid";
crmForm.all[fieldname].style.paddingRight="5px";
crmForm.all[fieldname].style.borderTop="#3366cc 1px solid";
crmForm.all[fieldname].style.paddingLeft="5px";
crmForm.all[fieldname].style.fontSize="11px";
crmForm.all[fieldname].style.backgroundImage="url(/_imgs/btn_rest.gif)";
crmForm.all[fieldname].style.borderLeft="#3366cc 1px solid";
crmForm.all[fieldname].style.width=buttonwidth;
crmForm.all[fieldname].style.cursor="hand";
crmForm.all[fieldname].style.lineHeight="18px";
crmForm.all[fieldname].style.borderBottom="#3366cc 1px solid";
crmForm.all[fieldname].style.backgroundRepeat="repeat-x";
crmForm.all[fieldname].style.fontFamily="Tahoma";
crmForm.all[fieldname].style.height="20px";
crmForm.all[fieldname].style.backgroundColor="#cee7ff";
crmForm.all[fieldname].style.textAlign="center";
crmForm.all[fieldname].style.overflow="hidden";
crmForm.all[fieldname].attachEvent("onmousedown",push_button);
crmForm.all[fieldname].attachEvent("onmouseup",release_button);
crmForm.all[fieldname].attachEvent("onclick",functiontocall);
crmForm.all[fieldname].style.lineHeight="14px";
crmForm.all[fieldname+'_c'].style.visibility = 'hidden';
crmForm.all[fieldname].title=title;
window.focus();

function push_button(){
window.event.srcElement.style.borderWidth="2px";
window.event.srcElement.style.borderStyle="groove ridge ridge groove";
window.event.srcElement.style.borderColor="#3366cc #4080f0 #4080f0 #3366cc";
}

function release_button(){
window.event.srcElement.style.border="1px solid #3366cc";
}
}



// now the definition of the function to call on button click

function FunctionName()

{

// do something

}

Deserialize XML into an Instance of BusinessEntity

You may have a scenario where an XML representation of a BusinessEntity class needs to be parsed into an in-memory object. One example is parsing the XML representation of DynamicEntity into an instance of this class within a plug-in assembly.

This sample is a stand-alone application that demonstrates how this can be done. Included here are two sample XML files that can be successfully parsed by this application. The sample parses any BusinessEntity XML string, and if the entity is of the type DynamicEntity, its properties are printed to the console. Child entities such as calendar rules on a calendar are handled as well.



namespace CrmClient
{
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using DynamicEntity.CrmServer;

class App
{
public static void Main(string[] args)
{
App theApp = new App(args);

theApp.Run();
}

public App(string[] args)
{
_args = args;
}

private void Run()
{
if (_args.Length < 1)
{
Console.WriteLine("Usage: DynamicEntityTest ");
return;
}

string fileName = _args[0];
Console.WriteLine("Reading XML from file {0}", fileName);

// Use stream reader to display XML to be parsed.
StreamReader sr = new StreamReader(fileName);
string entityXml = sr.ReadToEnd();
Console.WriteLine("XML to be parsed:");
Console.WriteLine(new string('-', 60));
Console.WriteLine("{0}", entityXml);
Console.WriteLine(new string('-', 60));

// Re-open the stream so that position is at the beginning of XML.
sr = new StreamReader(fileName);

// De-serialize the XML stream using the .NET XmlSerializer class.
XmlRootAttribute root = new XmlRootAttribute("BusinessEntity");
root.Namespace
= "http://schemas.microsoft.com/crm/2006/WebServices";
XmlSerializer xmlSerializer
= new XmlSerializer(typeof(BusinessEntity), root);
BusinessEntity entity
= (BusinessEntity)xmlSerializer.Deserialize(sr);
// End of deserialization.

Console.WriteLine("Deserialized XML into object of type {0}",
entity.GetType().FullName);

DynamicEntity dynamicEntity = entity as DynamicEntity;
if (dynamicEntity != null)
{
DisplayDynamicEntity(dynamicEntity,
"de-serialized from XML string");
}
}

///
/// Displays DynamicEntity instance and its properties.
///

private void DisplayDynamicEntity(DynamicEntity entity,
string message)
{
const string LineFormat = " {0,-30}{1,-30}{2}";

Console.WriteLine("DynamicEntity {0}: {1} with {2} properties:",
message, entity.Name, entity.Properties.Length);

Console.WriteLine(LineFormat, "Property Name", "Property Type",
"Property Value");
Console.WriteLine(LineFormat, "---", "---", "---");

foreach (Property prop in entity.Properties)
{
Type propertyType = prop.GetType();

// Format property value based on property type.
string propertyValue = string.Empty;
if (propertyType == typeof(StringProperty))
{
propertyValue = string.Format("'{0}'",
((StringProperty)prop).Value);
}
else if (propertyType == typeof(CrmDateTimeProperty))
{
CrmDateTime dt = ((CrmDateTimeProperty)prop).Value;
propertyValue
= string.Format("'{0}' date='{1}' time='{2}'",
dt.Value, dt.date, dt.time);
}
else if (propertyType == typeof(KeyProperty))
{
Key key = ((KeyProperty)prop).Value;
propertyValue = string.Format("'{0:D}'", key.Value);
}
else if (propertyType == typeof(LookupProperty))
{
Lookup lookup = ((LookupProperty)prop).Value;
propertyValue
= string.Format("'{0:D}' name='{1}' dsc='{2}'",
lookup.Value, lookup.name, lookup.dsc);
}
else if (propertyType == typeof(StateProperty))
{
string state = ((StateProperty)prop).Value;
propertyValue = string.Format("'{0}'", state);
}
else if (propertyType == typeof(DynamicEntityArrayProperty))
{
DynamicEntity[] children
= ((DynamicEntityArrayProperty)prop).Value;
propertyValue
= string.Format("number of child entities: {0}",
children.Length);

Console.WriteLine(LineFormat, prop.Name, propertyType.Name,
propertyValue);

Console.WriteLine(new string('>', 30));

int nc = 1;
foreach (DynamicEntity child in children)
{
DisplayDynamicEntity(child,
message + " - child #" + nc.ToString());
nc++;
}

Console.WriteLine(new string('<', 30));

continue;
}
else if (propertyType == typeof(OwnerProperty))
{
Owner owner = ((OwnerProperty)prop).Value;
propertyValue
= string.Format("'{0}' name='{1}' type='{2}'",
owner.Value, owner.name, owner.type);
}
else if (propertyType == typeof(CrmBooleanProperty))
{
CrmBoolean boolean = ((CrmBooleanProperty)prop).Value;
propertyValue = string.Format("'{0}'", boolean.Value);
}
else if (propertyType == typeof(PicklistProperty))
{
Picklist picklist = ((PicklistProperty)prop).Value;
propertyValue
= string.Format("'{0}', name='{1}'", picklist.Value,
picklist.name);
}

Console.WriteLine(LineFormat, prop.Name, propertyType.Name,
propertyValue);
}
}

string[] _args;
}
}


Friday, November 02, 2012

CRM 2011 CS: Assigning Lookup value

C# assign the contact to an account.
//C# assign the contact to an account.

Entity account = new Entity("account");
account["name"] = "Test Account1";
EntityReference primaryContactId = new EntityReference("contact", contactId);
account["primarycontactid"] = primaryContactId;

CRM 2011 CS: get String from a Lookup Field in crm 2011


//C# get String from a Lookup Field in crm 2011

((EntityReference)item.Attributes["new_lookup"]).Name



//C# get ID from a Lookup Field in crm 2011

((EntityReference)item.Attributes["new_lookup"]).Id

Tuesday, October 30, 2012

CRM 2011 CS: create request to retrieve Webresource


//create request to retrieve Webresource

QueryByAttribute requestWebResource = new QueryByAttribute

{

EntityName = WebResource.EntityLogicalName,

ColumnSet = new ColumnSet(true),

};



requestWebResource.Attributes.AddRange("name");

requestWebResource.Values.AddRange("url/XML/TestData.xml");

WebResource webResource = null;

EntityCollection webResourceCollection = organizationService.RetrieveMultiple(requestWebResource);

if (webResourceCollection.Entities.Count == 0)

throw new InvalidPluginExecutionException("Specified Webresource does not exist");

webResource = (WebResource)webResourceCollection.Entities[0];



byte[] binary = Convert.FromBase64String(webResource.Attributes["content"].ToString());

string resourceContent = UnicodeEncoding.UTF8.GetString(binary);

CRM 2011 CS: Query to get All Records


// Query to get All Records

protected EntityCollection getROBs(string EntityName)
{
CreatOrgSvcProx cosp = new CreatOrgSvcProx();
OrganizationServiceProxy prox = cosp.getServiceProxy();
ColumnSet _all = new ColumnSet(true);
QueryExpression _robQuery = new QueryExpression(EntityName);
_robQuery.ColumnSet = _all;
EntityCollection _allRec = prox.RetrieveMultiple(_robQuery);
return _allRec;
} //