March 4th, 2010
When I tried to add more address into an account in CRM, I keep getting this error with error message that doesn’t really help you nail down the problem. If you face the same error or you want to know how to create customeraddress using CRM 4.0 SDK DynamicEntity, please read through. The following simple code highlight how to add address into an account (You can also do on contact by changing the entity name “account” to “contact”. Please note that the values (i.e. street1, street2, city, …) is already set.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| var newAddress = new DynamicEntity
{
Name = NameOfEntity,
Properties = new PropertyCollection()
};
var prop = newAddress.Properties;
string addressName = street1 + " " + street2 + " " + city;
prop.Add(new StringProperty("name", addressName));
prop.Add(new StringProperty("line1", street1));
prop.Add(new StringProperty("line2", street2));
prop.Add(new StringProperty("city", city));
// .... add other details as necessary ....
prop.Add(new StringProperty("fax", fax));
prop.Add(new StringProperty("primarycontactname", contactName));
// .... this is the important property that you should add ...
prop.Add(new EntityNameReferenceProperty(AttrObjectType, new EntityNameReference("account")));
prop.Add(new LookupProperty(AttrParent, new Lookup("account", parentId)));
var targetCreate = new TargetCreateDynamic {Entity = newAddress};
var request = new CreateRequest {Target = targetCreate};
var response = (CreateResponse)CrmServiceUtil.GetCrmService().Execute(request);
return response.id; |
Rule of thumb, do not forget to set the ParentId attribute, as well as ObjectTypeCodeId. That should do the trick. The above code uses .NET 3.0.
Posted in Microsoft Dynamic CRM | No Comments »
November 19th, 2009
By using Microsoft Dynamic 4.0 form script capabilities, you can easily get the current user role. This ability will help you to create custom javascript to provide another level of user interaction. The script below will give you an example to grab all the roles assigned to the current CRM user.
First of all to make our life easier, as we do not need to reinvent the wheel (creating library to connect to CRM Web Service). Thanks to the guys at Ascentium, they have created a Microsoft Dynamics CRM JavaScript SDK which you can freely download at:
http://xrm.ascentium.com/blog/crm/Post129.aspx
For this example purpose, Copy and paste the Acentium CRM SDK javascript to the Form Onload of any entity.
Then below that, we can add our own code that refer to the script. Copy and paste the following.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // BEGIN: ferolen get the crrent user role scripts
var VALID_ROLENAME = "AdminGuy";
if (! UserHasRole(VALID_ROLENAME)) {
// Do something if the user does not have the role
}
function UserHasRole(roleName)
{
//create the Ascentium_CrmService object
var oService = new Ascentium_CrmService();
var xml = " ";
var aoFetchResult = oService.Fetch(xml);
for (var i = 0; i < aoFetchResult.length; i++) {
var beResult = aoFetchResult[i];
if (beResult.attributes["name"].value == roleName) return true;
}
return false;
}
// END : ferolen get the crrent user role scripts |
Posted in Uncategorized | No Comments »
July 29th, 2009
This tutorial is intended for restoring backup in Microsoft SQL Server 2005 by using Microsoft SQL Server Management Studio Express. Some of you might have tried tweaking around using the GUI of SQL Server Management Studio to restore the backup file. Most of junior developer will face this error:
Error 3154: The backup set holds a backup of a database other than the existing database.
Ok, let’s get into our business. First of all get the backup file (*.bak) and the tool (Microsoft SQL Server Management Studio Express) ready.
You should create the database (with the same file name *.mdf & *.ldf) which has the same name to your backup file.
The easiest way to do this, is try to open your backup file and figure out what is the database name, database file name ( ???.MDF), and log file name (???.LDF). On your Object Explorer right click the “Databases”, choose “Restore Database”, select “From Device”, and browse your *.bak file.
Once you get that, create new database with the same Database name and change the Logical name accordingly.
Once the database has been setup run the following query:
RESTORE DATABASE YOUR_DATABASE_NAME
FROM DISK = ‘C:\PATH_TO_YOUR_BACKUP\YOUR_BACKUP_FILE.bak‘
WITH REPLACE
Posted in SQL Server 2005 | No Comments »
July 16th, 2009
Are you getting the following errors message when using Dreamweaver CS4? (Note that it may happen to Dreamweaver Professional 8 and CS3 as well).
The following translators were not loaded due to errors:
_________.htm: has configuration information that is invalid.
….
In my case it also generate the following error message when you start and close dreamweaver.
while executing onLoad in RecordsetFind.htm, the following JavaScript error(s) occured:
In file “RecordsetFind”:
findRs is not defined
While executing onLoad in TeamAdminTempDelete.html, the following JavaScript error(s) occured:
In file “TeamAdminTempDelete”:
delTempFile is not defined
It turns out that there is something wrong with your Dreamweaver configuration files. It may be caused by file corrupt, or changes in your system.
To solve this you will have to remove the current configuration folders, so that Dreamweaver will generate new one for you. To do that, close your Dreamweaver and go to the following folder:
C:\Documents and Settings\YOUR_WINDOWS_USERNAME\Application Data\Adobe\Dreamweaver CS4\en_US
Rename the “Configuration” folder in to “Configuration-old”, and then fire up your Dreamweaver.
It should generate the new Configuration folder. Now you might loose your last configuration such as the sidebar width, last used view, etc.
Posted in IT, Web Development | 23 Comments »
June 17th, 2009
Usually, we can search and identify PHP function just by looking at it’s name which denotes what a function does. For example array_pop(), array_push(), array_search(), array_reverse(), etc. But how about inserting an element into the middle of an array?
array_splice(array &$input, int $offset [, int $length= 0 [, mixed $replacement]] ) is the function that you are looking for. Format to use this function to add new element at certain position in an array is array_splice($array, $insert_position, 0, $element_to_insert);. See below for an example of how this function behaves.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")
$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green", "blue", "black", "maroon")
$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green", "blue", "purple", "yellow");
?> |
Posted in Web Development | No Comments »