Get the Stage and Process of the Business Process

Hi,

Today we got a requirement to do some action based on Opportunity Stage.
 
Even though there is a field as stepname on the Opportunity entity. I see that field is not updated all the times. So, here is the C# code for knowing the Stage of the record.
 

string strStageName = string.Empty;

// Get StageId, ProcessId of the record.
QueryExpression objQueryExpr = new QueryExpression(“opportunity”);
objQueryExpr.Criteria.AddCondition(new ConditionExpression(“opportunityid”, ConditionOperator.Equal, “”));
objQueryExpr.ColumnSet = new ColumnSet(new string[] { “stepname”, “stageid”, “processid” });

EntityCollection entColProcessStages = iService.RetrieveMultiple(objQueryExpr);

// Query Process Stage by passing StageId and get the name of the stage.
QueryExpression objQueryExpr1 = new QueryExpression(“processstage”);
objQueryExpr1.Criteria.AddCondition(new ConditionExpression(“processid”, ConditionOperator.Equal, entColProcessStages.Entities[0].Attributes[“processid”]));
objQueryExpr1.ColumnSet = new ColumnSet(true);
entColProcessStages = iService.RetrieveMultiple(objQueryExpr1);
if (entColProcessStages != null && entColProcessStages.Entities.Count > 0)
{
     strStageName = entColProcessStages.Entities[0][“stagename”].ToString();
}

Hope this helps.


Happy CRM’ing
Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s