Here is a quick snippet of javascript code to get the GUID of the current CRM form:
crmForm.ObjectId
Thursday, September 6, 2007
Getting values from a lookup control
We recently needed to capture both the GUID and the text value from a CRM lookup control. I found some quick code to do this on the following newsgroup:
http://groups.google.com/group/microsoft.public.crm/browse_thread/thread/9bc6721768f0a1f1/4b5f5d0ff5972dc0?lnk=st&q=ms+crm+get+lookup+datavalue&rnum=1&hl=en#4b5f5d0ff5972dc0
var lookupItem = new Array;
lookupItem = crmForm.all.primarycontactid.DataValue;
if (lookupItem[0] != null)
{
// The text value of the lookup.
alert(lookupItem[0].name);
// The GUID of the lookup.
alert(lookupItem[0].id);
}
http://groups.google.com/group/microsoft.public.crm/browse_thread/thread/9bc6721768f0a1f1/4b5f5d0ff5972dc0?lnk=st&q=ms+crm+get+lookup+datavalue&rnum=1&hl=en#4b5f5d0ff5972dc0
var lookupItem = new Array;
lookupItem = crmForm.all.primarycontactid.DataValue;
if (lookupItem[0] != null)
{
// The text value of the lookup.
alert(lookupItem[0].name);
// The GUID of the lookup.
alert(lookupItem[0].id);
}
Friday, July 6, 2007
Set Datetime field using Javascript
Here is the code to set the date and time of a datetime field using Javascript. You can put this into your onLoad event handler.
var today = new Date( );
today.setHours(14);
today.setMinutes(00);
crmForm.all.new_datefield.DataValue = today;
var today = new Date( );
today.setHours(14);
today.setMinutes(00);
crmForm.all.new_datefield.DataValue = today;
Tuesday, June 26, 2007
Dynamically Changing an IFrame URL
Here is the code to dynamically change an IFrame URL. Put this code in your onLoad event handler on a form:
var ProcessID = crmForm.all.new_fieldname.DataValue;
IFRAME_report.location='http://www.google.com';
You can also hide an IFrame onLoad and display it when needed by including the following code:
crmForm.all.IFRAME_report.style.display = 'none';
var ProcessID = crmForm.all.new_fieldname.DataValue;
IFRAME_report.location='http://www.google.com';
You can also hide an IFrame onLoad and display it when needed by including the following code:
crmForm.all.IFRAME_report.style.display = 'none';
Wednesday, June 20, 2007
Creating a button to call any Actions Menu function
I found a way to call the "Apply Rule" window and pass all the necessary parameters from a button on the form. This procedure can be used though to call any Actions Menu fuction on a form. Below is example code that creates a button on a custom entity. Place this code in the isv.config.xml file. The key piece of code is the JavaScript parameter value: onActionMenuClick('applyrule', 10023)
The only thing you have to change is the ObjectId (10023 in the sample code below).
The only thing you have to change is the ObjectId (10023 in the sample code below).
<Entity name="new_snapshot">
<ToolBar ValidForCreate="0" ValidForUpdate="1">
<Button Title="Run Process" ToolTip="Run Data Process" Icon="/_imgs/ico_18_4405.gif" Url="" JavaScript="onActionMenuClick('applyrule', 10023)" PassParams="0" WinParams="" AvailableOffline="false" WinMode="1"/>
</ToolBar>
</Entity>
To call any other Actions Menu function, open up the form you want to the button on, view the html source of the form and search for the the Actions Menu fuction (e.g. Deactivate). Copy the JavaScript function into the JavaScript tag on a button.
Thursday, May 31, 2007
Converting DynamicEntity to a Core Entity
Microsoft was very kind. They gave the us the power of the DynamicEntity. Very handy. They also give us the hard-typed "core" entity objects.
In the case of callouts core entities are not used and only dynamic entities are passed to the callout functions. Working with DynamicEntities though can be a pain, especially when it comes to changing one field and updating the record back in CRM. Since there is no direct access to a specific field, if you want to update a field you need to step through each of the Properties on the DynamicEntity until you find the one you want. Not real efficient if you ask me.
So, this is where having a hard-typed "core" entity comes in handy. But how do you convert? EASY! Well, sorta easy. You see, MS provided a great little code snippet in the CRM SDK for doing such a conversion. It's right here.
However, there is one little problem with this.
So I started to play with this by creating a real simple test app and then retrieving an account DynamicEntity:
tempService.Url = @"http://danubecrm:5555/MSCRMServices/2006/crmservice.asmx";
tempService.Credentials = new System.Net.NetworkCredential("administrator","pass@word1","crmdomain");
RetrieveRequest getEntity = new RetrieveRequest();
TargetRetrieveDynamic target = new TargetRetrieveDynamic();
target.EntityId = new Guid("f0705cff-1e0f-dc11-99e2-0003ff2689b7");
target.EntityName = "account";
getEntity.Target = target;
getEntity.ColumnSet = new AllColumns();
getEntity.ReturnDynamicEntities = true;
RetrieveResponse response = (RetrieveResponse) tempService.Execute(getEntity);
DynamicEntity tempDynamicEntity = (DynamicEntity)response.BusinessEntity;
And then I fed it into the Convert function. CRASH!
It turns out that the DynamicEntity comes back with the StateCode field being a "StateProperty" type. However, on the account object the StateCode field is an AccountStateInfo type. When the reflection methods tried to write the String value that came from the StateProperty.Value, it crashed cause there is no implicit converstion between a String and a AccountState object.
So I modified the code conversion routines to ignore this field. I'm sure there is a better solution but right now there is a project to get done and I don't need to know the StateCode of the account to get it done.
In the case of callouts core entities are not used and only dynamic entities are passed to the callout functions. Working with DynamicEntities though can be a pain, especially when it comes to changing one field and updating the record back in CRM. Since there is no direct access to a specific field, if you want to update a field you need to step through each of the Properties on the DynamicEntity until you find the one you want. Not real efficient if you ask me.
So, this is where having a hard-typed "core" entity comes in handy. But how do you convert? EASY! Well, sorta easy. You see, MS provided a great little code snippet in the CRM SDK for doing such a conversion. It's right here.
However, there is one little problem with this.
So I started to play with this by creating a real simple test app and then retrieving an account DynamicEntity:
tempService.Url = @"http://danubecrm:5555/MSCRMServices/2006/crmservice.asmx";
tempService.Credentials = new System.Net.NetworkCredential("administrator","pass@word1","crmdomain");
RetrieveRequest getEntity = new RetrieveRequest();
TargetRetrieveDynamic target = new TargetRetrieveDynamic();
target.EntityId = new Guid("f0705cff-1e0f-dc11-99e2-0003ff2689b7");
target.EntityName = "account";
getEntity.Target = target;
getEntity.ColumnSet = new AllColumns();
getEntity.ReturnDynamicEntities = true;
RetrieveResponse response = (RetrieveResponse) tempService.Execute(getEntity);
DynamicEntity tempDynamicEntity = (DynamicEntity)response.BusinessEntity;
And then I fed it into the Convert function. CRASH!
It turns out that the DynamicEntity comes back with the StateCode field being a "StateProperty" type. However, on the account object the StateCode field is an AccountStateInfo type. When the reflection methods tried to write the String value that came from the StateProperty.Value, it crashed cause there is no implicit converstion between a String and a AccountState object.
So I modified the code conversion routines to ignore this field. I'm sure there is a better solution but right now there is a project to get done and I don't need to know the StateCode of the account to get it done.
Monday, May 14, 2007
Using QueryExpressionHelper to get a Contact's GUID
Here is an example of how to use QueryExpressionHelp to get a Contact's GUID.
QueryExpressionHelper queryHelper = new QueryExpressionHelper(EntityName.contact);
queryHelper.Columns.AddColumn("contactid");
queryHelper.Criteria.Conditions.AddCondition("FieldNameFromEntity", ConditionOperator.Equal, thisIsTheParameter);
queryHelper.Criteria.FilterOperator = LogicalOperator.And;
BusinessEntityCollection coll = service.RetrieveMultiple(queryHelper.Query);
contact user = (contact)coll.BusinessEntities[0];
Guid syscoGuid = user.contactid.Value.ToString();
QueryExpressionHelper queryHelper = new QueryExpressionHelper(EntityName.contact);
queryHelper.Columns.AddColumn("contactid");
queryHelper.Criteria.Conditions.AddCondition("FieldNameFromEntity", ConditionOperator.Equal, thisIsTheParameter);
queryHelper.Criteria.FilterOperator = LogicalOperator.And;
BusinessEntityCollection coll = service.RetrieveMultiple(queryHelper.Query);
contact user = (contact)coll.BusinessEntities[0];
Guid syscoGuid = user.contactid.Value.ToString();
Subscribe to:
Posts (Atom)