CRM Blog

March 2009 - Posts

Example Of Deactivating An Entity
by Danny Varghese 03.06.09

Comments    2 Comment(s)

One of the least published example of CRM code is deactivating an entity, probably because it's not used as often as creating, updating or retrieving entities.  Below is an example I've used on several occasions to deactivate an entity:

 

public void DeactivateEntity(Guid entityId)

{

//variable initialization

            SetStateDynamicEntityRequest deactivateReq = new SetStateDynamicEntityRequest();   

 

            //deactivate the cloned assignment

            deactivateReq = new SetStateDynamicEntityRequest();

            deactivateReq.State = "Inactive";

            deactivateReq.Status = 2;

            deactivateReq.Entity = new Moniker();

            deactivateReq.Entity.Name = <entity name>

            deactivateReq.Entity.Id = entityId;

 

//execute the deactivation request

            service.Execute(deactivateReq);

}

Filed under:
Example of Dynamic Entity Update
by Danny Varghese 03.05.09

Comments    No Comments

I have seen numerous requests on other blogs about sample code to on how to update entities in CRM.  One way is to use the CRM web service to update business entities, however by doing so, you're only limited to out-of-the-box entities with system attributes.  To retrieve anything more "dynamic," you'll have to employ other methods.  Please remember that in order to update any record, you must have the proper permissions on that entity.

 

Below is a code example of how to update a record:

 

public void UpdateEntity(ICrmService service)

{

//variable initialization

            DynamicEntity entity = new DynamicEntity();                                                     //target entity to update

            TargetUpdateDynamic targetUpdate = new TargetUpdateDynamic();      //used to update entity

            UpdateRequest updateRequest = new UpdateRequest();                            //request to update entity

 

entity.Name = <entity name>

 

//add the properties you want to update on the entity

entity.Properties.Add(<property1>);

entity.Properties.Add(<property2>);

entity.Properties.Add(<property3>);

             

//set the target to update, and the request to update for

targetUpdate.Entity = entity;

updateRequest.Target = targetUpdate;

 

//execute the update request

service.Execute(updateRequest);

}

Filed under:
E-mail Field - Open In Outlook or E-mail Activity
by Danny Varghese 03.04.09

Comments    9 Comment(s)

Here's a simple JavaScript customization to enable an e-mail field, once filled in, have a user double-click it and open your default e-mail client with the address in the "To" field.

 

if(crmForm.FormType == 1 || crmForm.FormType == 2)

{

                crmForm.all.emailaddress1.ondblclick = function()

                {

                                var email = crmForm.all.emailaddress1.DataValue;

                                if ((email != null) && (email.length > 0))

                                {

                                     window.navigate("mailto:" + email);

                                }

                                                               

                }

}

 

Now if you want to make CRM open an e-mail activity instead of the default e-mail client, you can use the following code (when sending the email, CRM will use email address 1 regardless of what field was dobule clicked):

 

if(crmForm.FormType == 1 || crmForm.FormType == 2)

{

                crmForm.all.emailaddress1.ondblclick = function()

                {

                                var email = crmForm.all.emailaddress1.DataValue;

                                if ((email != null) && (email.length > 0))

                                {

                                     window.execScript(locAddActTo(4202))

                                }

                                                               

                }

}

Filed under:
Example of Dynamic Entity Create
by Danny Varghese 03.04.09

Comments    No Comments

There have been numerous requests on other blogs about sample code to on how to create entities in CRM.  One way is to use the CRM web service to create business entities, however by doing so, you're only limited to out-of-the-box entities with system attributes.  To retrieve anything more "dynamic," you'll have to employ other methods.  Please remember that in order to create any record, you must have the proper permissions on that entity.

 

Below is a code example of how to create a record using dynamic entities:

 

public void CreateEntity(ICrmService service)

{

//variable initialization

DynamicEntity entity = new DynamicEntity();                                                 //target entity to update

TargetCreateDynamic targetCreate = new TargetCreateDynamic();          //used to update entity

CreateRequest createRequest = new CreateRequest();                                //request to create entity

 

entity.Name = <entity name>

 

//add the properties                   

entity.Properties.Add(<property>);

Entity.Properties.Add(<property>);

 

//set the target to update, and the request to update for

targetCreate.Entity = entity;

createRequest.Target = targetCreate;

 

//execute the update request

service.Execute(createRequest);

}

 

Hope this helps, happy coding!

Filed under: