Sunday, November 29, 2009

Allow to CRM 4.0 to pass( add) parameters to query string.

Hi,
CRM 4.0 disabled option to add parameters in query string.

to change this option need to change register.
goto Start - Run write -> regedit ( register)

Edit the registry in:
HKEY_Local_Machine\Software\Microsoft\MSCRM
Add a new DWORD
"DisableParameterFilter"
set value to 1.‬

this changes will help to add parameters in query string.

Enjoy,
Rami Heleg

Tuesday, November 17, 2009

Create Annotation with File

Here is an example to create Annotation:

annotation n = new annotation();

n.objectid = new Lookup();
//define to which entity
n.objectid.Value = new Guid(EntityId);
attach to specific entity
n.objecttypecode = new EntityNameReference();
n.objecttypecode.Value = EntityType;

//Create
Guid noteID = pService.Create(n);

//open and read file
FileInfo file = new FileInfo(fileP);
FileStream fs = file.OpenRead();
byte[] byteData = new byte[fs.Length];
fs.Read(byteData, 0, byteData.Length);
fs.Close();

string encodedData = System.Convert.ToBase64String(byteData);

//Create the Request Object
UploadFromBase64DataAnnotationRequest upload = new
UploadFromBase64DataAnnotationRequest();

//Set the Request Object's Properties
upload.AnnotationId = noteID;
upload.FileName = file.Name;
upload.MimeType = "text/plain";
upload.Base64Data = encodedData;

//Execute the Request
UploadFromBase64DataAnnotationResponse uploaded =
(UploadFromBase64DataAnnotationResponse)pService.Execute(upload);


Entity contain annotation + file.

enjoy,
Rami Heleg

Thursday, November 12, 2009

Use setInterval, clearInterval in CRM 3/4

Using setInterval if very helpful and powerfull when develop javascript in CRM 3/4.

Special target is to load forms very fast and make other code after user start to work.

This example contain two functions.
loadMyPage() and afterLoading()

function loadMyPage() call to function afterLoading() with interval of one second.

After second function afterLoading() is working..

Don’t forget to make the clearInterval.. clear calling.

function afterLoading() {
window.clearInterval(common_init_interval);
}

function loadMyPage(){
common_init_interval = setInterval('try { afterLoading (); } catch (e) { }', 1000);
}


Enjoy,
Rami Heleg

Handle Grid in IFRAME

Here is an example how to handle grid (like area grid) in IFRAME.

Add these 2 rows where form is loaded to get handle of the iframe


var iframe = document.getElementById('IFRAME_test');
iframe.onreadystatechange = FrameStateChanged;


function to handle iframe state changed like initalize, complete

function FrameStateChanged()
{
var iframe = document.getElementById('IFRAME_test');
if(iframe.readyState == "complete"){
// get grid from iframe
caseGrid = iframe.contentWindow.document.getElementById('crmGrid');
if (caseGrid != null)
caseGrid.attachEvent("onselectionchange",HandleGridSelectionChange);
}
}

// get guid from selected row.. can get all values.
function HandleGridSelectionChange()
{
//select row
var selectedRow = caseGrid.InnerGrid.SelectedRecords;
// get selected guid
if (selectedRow.length > 0)
var guid =selectedRow[0][0];

}


Enjoy,
Rami Heleg

Saturday, November 7, 2009

Replace tags to support legal JS page

The options to change string to be XML legal value:




Thanks,
Rami Heleg

Wednesday, November 4, 2009

Call from Javascript to Server via WCF/XML

Here is a simple example of calling to server from javascript side based WCF,XML

This example contain 3 options:
· Return string from server
· Return object from server
· Send object to server

1. create a new project name = ‘wcf2’

2. add new aspx page name Default.aspx.

3. paste code to javascript:






4. create new wcf service name 'Service.svc'

5. paste code the interface fileusing System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;

// NOTE: If you change the interface name "IService" here, you must also update the reference to "IService" in Web.config.
[ServiceContract]
public interface IService
{
[OperationContract]
string GetsProperty1();
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/Person")]
Person GetDTO();

///
/// This is not working a real post. it still goes to the quesry string
///

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Person2?Property1={sProperty1}&Property2={nProperty2}&Property3={bProperty3}")]
Person GetDTO2(string sProperty1, int nProperty2, bool bProperty3);

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Person4?Property1={sProperty1}&Property2={nProperty2}&Property3={bProperty3}")]
Person GetDTO4(string sProperty1, int nProperty2, bool bProperty3);
}

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class Person
{
[DataMember]
public string sProperty1 = "123";

[DataMember]
public int nProperty2 = 123;

[DataMember]
public bool bProperty3 = true;

}

6. paste code to service fileusing System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Text;
using System.IO;

// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file.
public class Service : IService
{
private Person oPerson = new Person();

public string GetsProperty1()
{
return oPerson.sProperty1;
}
public Person GetDTO()
{
return this.oPerson;
}

public Person GetDTO2(string sProperty1, int nProperty2, bool bProperty3)
{
return this.oPerson;
}

public Person GetDTO4(string sProperty1, int nProperty2, bool bProperty3)
{
return this.oPerson;
}

public int GetDTO3(string sProperty1, int nProperty2, bool bProperty3)
{
return 590;
}
}
7. run project when default.aspx file is the startup page....
good luck,
Rami Heleg

Tuesday, November 3, 2009

Allow to Work with all CRM DB tables

Hi

I try to ask tables in CRM which I am not Authorized to ask.. what can I do?

You need to wrap the Query, Insert etc with this example


WindowsImpersonationContext impersonation = WindowsIdentity.Impersonate(IntPtr.Zero);
try {
// my code
} finally {
impersonation.Undo();
}

This solution will help you to work with all Database, CRM tables.

Enjoy,
Rami Heleg

How to get systemuser details in Plugin

Hi,
Here is an example how to get data in plugin code from server.
the example used to get info from systemuser table, but can be for every type of entity.


public static string GetUserFullName(IPluginExecutionContext context) {
try {
ICrmService service = context.CreateCrmService(false);
ColumnSetBase columns = new AllColumns();
systemuser oSystemUser = (systemuser)service.Retrieve("systemuser", context.UserId, columns);
return oSystemUser.fullname;
} catch (Exception ex) {
return ex.Message;
}


Enjoy,
Rami Heleg

Property ForceSubmit

CRM Send parameters from client to server only if IsDirty = true, it means fields has been changed.

this issue good for performance.
to send field value any way to server need to change field property like this example:
crmForm.all.firstname.ForceSubmit = true;

like that if field is disabled or contain the same value the value sent any way to server.

thanks,
Rami Heleg.