Identifying workflow context
To identify the general workflow context in create scripts, validate scripts and table level scripts, use the following code:
if (CRM.GetContextInfo("company","comp_companyid"))
{
Valid = false;
ErrorStr = "We are in company context";
}
However, a workflow can have different starting points because you can define multiple primary workflow rules. A primary workflow rule is displayed as a New button in the UI. You can control which New button is displayed by defining a JavaScript condition for the rule. In this case, you must know the primary workflow context to ensure you display the correct button.
To identify the primary workflow context, check the Key0 value in the QueryString of the URL. In a workflow primary rule you can access this with the Values() collection. The following example checks the workflow context and if it is the primary context of the company, the rule is not displayed.
if (Values("key0")==1)
{
// Then we are in company prime context.
}
if (Values("key0")==2)
{
// Then we are in person prime context.
}
