Wednesday, January 19, 2011

Save multiple choice values in SharePoint ListItem

You will find that your checkbox list is populated with the selected value.
Save selected checkboxes in the list item as below



SPFieldMultiChoiceValue multiValue = new SPFieldMultiChoiceValue();
foreach (ListItem item in multiValueInputFormCheckBoxList.Items)
{
if (item.Selected) multiValue.Add(item.Value);
}
item["multivalued choice field name"]= multiValue;


Happy Coding !!!

Display multiple choice value of saved Listitem

Show those values which was stored in the SharePoint ListItem.
For display selected value use previous post’s “InputFormCheckBoxList”
Select listitem for display choice field’s multiple value as below



if (item["multivalued choice field name"] != null)

{

SPFieldMultiChoiceValue multiValue = new SPFieldMultiChoiceValue(item["multivalued choice field name"]);

for (int i=0; i<= multiValue.Count; i++) multiValueInputFormCheckBoxList.Items.FindByText(multiValue[i]).Selected = true; }


Happy Coding !!!

Bind SharePoint multiple choice field in custom form

Bind SharePoint multiple choice field in custom form.

You can bind sharepoint multiple choice value in sharepoint check box list control for display Choice field values.
Add SharePoint “InputFormCheckBoxList” and bind as below code.


ASPX Design Code:




Use below code to populate the choice column values in above control.
Server Side CS Code:

// -------------- Populate CheckBox List
SPField multiValueCheckBoxField = objSPList.Fields["multivalued choice field name"];
SPFieldMultiChoice multiValueCheckBoxChoicesField = (SPFieldMultiChoice) multiValueCheckBoxField ;

// for each loop for values add in checkbox list
foreach (string choiceValue in multiValueCheckBoxChoicesField.Choices)
{
this.multiValueInputFormCheckBoxList.Items.Add(new ListItem(choiceValue, choiceValue));
}


Happy Coding!!!

Tuesday, January 18, 2011

Error occurred in deployment step 'Add Solution': Failed to extract the cab file in the solution.

Error Message: Error occurred in deployment step 'Add Solution': Failed to extract the cab file in the solution.

One day I tried to deploy Images in _layouts folder using VS 2010. But I couldn't deploy Images because above error message fired in VS2010's error window. After half and hour I found one file named with blue_button (2).gif and renamed with blue_button.gif and deploy solution. Its working fine.

Resolution: To work around this problem, remove any parentheses in the names of SharePoint project items.

This link help me to solve the problem http://msdn.microsoft.com/en-us/library/ee330922.aspx.

Happy Coding !!!

Saturday, January 8, 2011

Programmatically set Picklist Option value in CRM Entity Item

In my older post I have collect Picklist options in DropDownList.
So now I save this DropDown’s selected value in CRM’s Entity Item’s Attribute.
You can’t save option in Entity Item, without picklist’s Value & Text. Means you have to provide Option’s Value & Options Text.
Also you have to create a new instance of the picklist before setting the value.
See the below sample code snippet for set the picklist option value.


CrmSdk.new_customentity newcustomentity = new CrmSdk.new_customentity();//Custom Entity's obj

newcustomentity.new_entityattribute = new CrmSdk.Picklist();//Creating New Instance before assign Value & Text
newcustomentity.new_entityattribute.Value = Convert.ToInt32(objDropDownList.SelectedItem.Value); //Set DropDownList's Value
newcustomentity.new_entityattribute.name = objDropDownList.SelectedItem.Text;//Set DropDownList's Text


Happy Coding!!!

Programmatically Getting CRM Entiry Picklist Option value

Whenever use picklist in CRM Entity’s Attribute you have to collect all picklist options in any collections like ArrayList, HashTable OR controls like DropDownList, ListBox etc. for display Options in UI.
For collecting Picklist Options you have to use CRM’s MetaDataService.asmx as older Post.
See the below sample code snippet for collect picklist options.




RetrieveAttributeRequest request = new RetrieveAttributeRequest();//Create Obj for RetrieveAttributeRequest

request.EntityLogicalName = CrmSdk.EntityName.new_crmcustomentity.ToString();//Assign CRM's Custom Entity

request.LogicalName = "new_customattribute";//Set Obj's Picklist Attribute Name



//Now collect entity's response using Metadataservice execution

RetrieveAttributeResponse response = (RetrieveAttributeResponse)service.Execute(request);//service is MetaDataService.asmx's object

//collect Picklist Attribute Metadata value

PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;



//here I use DropDownList for collecting PickList Options

foreach (Option o in picklist.Options)

{

objDropDownList.Items.Add(new ListItem(o.Label.UserLocLabel.Label, o.Value.Value.ToString()));

}


In my Next Post you will see how to set Picklist Option in CRM Entity Item from Custom UI.

Happy Coding !!!

Thursday, January 6, 2011

Programmatically Create MS CRM Account

Using CRM SDK4.0 you can customize CRM programmatically.
Download CRMSDK 4.0 from here
http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=en
Then add web service reference in your project
Example:
http://CrmApplicationUrl/MSCRMServices/2007/CrmService.asmx
Also you have to pass below Items in CRM Code.
- Organization Name

- Username, Password & Domain (CRM Credential)
See the below function code for CRM Account Creation.




public static void createAccount(string NewAccountName)
{
CrmSdk.CrmService myCrm = new CrmSdk.CrmService();
myCrm.Url = "http://CrmApplicationUrl/MSCRMServices/2007/CrmService.asmx";

CrmSdk.CrmAuthenticationToken myCrmToken = new CrmSdk.CrmAuthenticationToken();
myCrmToken.AuthenticationType = 0;
myCrmToken.OrganizationName = GetCrmOrganization();//"OrganizationName";

myCrm.CrmAuthenticationTokenValue = myCrmToken;

System.Net.NetworkCredential nc = new System.Net.NetworkCredential();
nc.UserName = "Username";//Pass Username of CRM
nc.Password = "Password";//Pass Password of above CRMAccount
nc.Domain = "Domain";//Pass Domain name

myCrm.Credentials = nc;
CrmSdk.account newAccount = new CrmSdk.account();

newAccount.name = NewAccountName;
Guid newAccountId = myCrm.Create(newAccount);
}



Happy coding !!!