Wednesday 13 September 2017

Changing systemuser status and associating a role

Aim: To change the systemuser status from active to inactive and associate a role with a systemuser.

The following two C# methods demonstrate how to change the systemuser state from active to inactive and vice versa. The second method shows how to associate a role with a systemuser.


For changeUserStatus method you will also need to include the Microsoft.CRM.SDK DLL as well since the SetStateRequest message is present here.


The changeUserStatus method shows how to change to user state from active to inactive or from inactive to active. You need to pass the systemuser GUID whose state needs to be changed, the organization service and the state you want to change the user to. State takes a int parameter (1 is for inactive and 0 is for active)


In CRM changing the system user state is done through the SetStateRequest. SetStateSystemUserRequest was used in earlier versions of CRM and is deprecated now.




 private void changeUserStatus(Guid userId, IOrganizationService service,int state)

 {         
      SetStateRequest setStateRequest = new SetStateRequest{
                  EntityMoniker = new EntityReference("systemuser", userId),
                   State = new OptionSetValue(state),//1=disabled, 0=enabled
                   Status = new OptionSetValue(-1),
                   };
       service.Execute(setStateRequest);
               
 }



The associateRoleWithUser method associates a role with a user. You need to pass the system user GUID and role GUID between for which the association needs to be created. The relationship name also needs to be passed. This is the name by which the relationship will be displayed in the Customizations in CRM UI.


 private void associateRoleWithUser(Guid userId, IOrganizationService serviceGuid role, string relationshipName)

 {
                    
 //Create the associate request
 AssociateRequest associate = new AssociateRequest();

 //This is the systemuser that is being associated to a role  

 associate.RelatedEntities = new EntityReferenceCollection();
 associate.RelatedEntities.Add(new EntityReference("systemuser", userId));

 //Target is the entity to which we are associating the systemuser i.e. role and its GUID.

 associate.Target = new EntityReference("role", role);           

//This is the schema name in CRM that is used while associating entities.                

associate.Relationship = new Relationship(relationshipName);

service.Execute(associate);


}

Wednesday 8 March 2017

Entity Statecodes and Statuscodes

AIM: To list down the statecodes and statuscodes of the commonly used entities. 

Recently I was trying to change the statecode of email and had a tough time finding the valid status' and status reasons.

Below is the list of the entity statecodes and statuscodes. Use Ctrl+F to find the entity by display name or schema name.


Entity
Status (statecode)
Associated Status Reason (statuscode)
Account (account)
0 Active
1 Active
1 Inactive
2 Inactive
Activity (activitypointer)
0 Open
1 Open
1 Completed
2 Completed
2 Canceled
3 Canceled
3 Scheduled
4 Scheduled
Appointment (appointment)
0 Open
1 Free
2 Tentative
1 Completed
3 Completed
2 Canceled
4 Canceled
3 Scheduled
5 Busy
6 Out of Office
Article (kbarticle)
1 Draft
1 Draft
2 Unapproved
2 Unapproved
3 Published
3 Published
Campaign (campaign)
0 Active
0 Proposed
1 Ready To Launch
2 Launched
3 Completed
4 Canceled
5 Suspended
Campaign Activity (campaignactivity)
0 Open
0 In Progress
1 Proposed
4 Pending
5 System Aborted
6 Completed
1 Closed
2 Closed
2 Canceled
3 Canceled
Campaign Response (campaignresponse)
0 Open
1 Open
1 Closed
2 Closed
2 Canceled
3 Canceled
Case (incident)
0 Active
1 In Progress
2 On Hold
3 Waiting for Details
4 Researching
1 Resolved
5 Problem Solved
2 Canceled
6 Canceled
Case Resolution (incidentresolution, notcustomizable)
0 Open
1 Open
1 Completed
2 Closed
2 Canceled
3 Canceled
Contact (contact)
0 Active
1 Active
1 Inactive
2 Inactive
Contract (contract)
0 Draft
1 Draft
1 Invoiced
2 Invoiced
2 Active
3 Active
3 On Hold
4 On Hold
4 Canceled
5 Canceled
5 Expired
6 Expired
Contract Line (contractdetail)
0 Existing
1 New
1 Renewed
2 Renewed
2 Canceled
3 Canceled
3 Expired
4 Expired
Currency (transactioncurrency)
0 Active
0 Active
1 Inactive
1 Inactive
Discount (discounttype)
0 Active
100001 Active
1 Inactive
100002 Inactive
E-mail (email)
0 Open
1 Draft
8 Failed
1 Completed
2 Completed
3 Sent
4 Received
6 Pending Send
7 Sending
2 Canceled
5 Canceled
Fax (fax)
0 Open
1 Open
1 Completed
2 Completed
3 Sent
4 Received
2 Canceled
5 Canceled
Invoice (invoice)
0 Active
1 New
2 Partially Shipped
4 Billed
5 Booked (applies to services)
6 Installed (applies to services)
1 Closed (deprecated)
3 Canceled (deprecated)
7 Paid in Full (deprecated
2 Paid
100001 Complete
100002 Parial
3 Canceled
100003 Canceled
Lead (lead)
0 Open
1 New
2 Contacted
1 Qualified
3 Qualified
2 Disqualified
4 Lost
5 Cannot Contact
6 No Longer Interested
7 Canceled
Letter (letter)
0 Open
1 Open
2 Draft
1 Completed
3 Received
4 Sent
2 Canceled
5 Canceled
Marketing List (list)
0 Active
0 Active
1 Inactive
1 Inactive
Opportunity (opportunity)
0 Open
1 In Progress
2 On Hold
1 Won
3 Won
2 Lost
4 Canceled
5 Out-Sold
Order (salesorder)
0 Active
1 New
2 Pending
1 Submitted
3 In Progress
2 Canceled
4 No Money
3 Fulfilled
100001 Complete
100002 Partial
4 Invoiced
100003 Invoiced
Phone Call (phonecall)
0 Open
1 Open
1 Completed
2 Made
4 Received
2 Canceled
3 Canceled
Price List (pricelevel)
0 Active
100001 Active
1 Inactive
10002 Inactive
Product (product)
0 Active
1 Active
1 Inactive
2 Inactive
Quote (quote)
0 Draft
1 In Progress
1 Active
2 In Progress
3 Open
2 Won
4 Won
5 Out-Sold
3 Closed
5 Lost
6 Canceled
7 Revised
Service Activity (serviceappointment)
0 Open
1 Requested
2 Tentative
1 Closed
8 Completed
2 Canceled
9 Canceled
10 No Show
3 Scheduled
3 Pending
4 Reserved
6 In Progress
7 Arrived
Task (task)
0 Open
2 Not Started
3 In Progress
4 Waiting on someone else
7 Deferred
1 Completed
5 Completed
2 Canceled
6 Canceled

Hide New... button on lookup controls in model-driven apps

  The 'New ...' button is shown upon opening the lookup search dialog whenever the logged in user has at least user create privileg...