Statecode and Statuscode – One can’t live without the other

Got a question today, which statecodes can have which stauscodes. There is no list in the latest Sdk like it used to be for MS CRM. So, looking around gave us a SQL revealing the answers:

select e.name, sm.State, smstate.Value , sm.Status, smstatus.Value ,sm.IsDefault
from StatusMap sm
inner join Entity e on e.objecttypecode = sm.objecttypecode
inner join StringMap smstate on smstate.AttributeName = 'statecode'
and smstate.ObjectTypeCode = sm.ObjectTypeCode
and smstate.LangId = 1033
and sm.State = smstate.AttributeValue
inner join StringMap smstatus on smstatus.AttributeName = 'statuscode'
and smstatus.ObjectTypeCode = sm.ObjectTypeCode
and smstatus.LangId = 1033
and sm.Status = smstatus.AttributeValue
where sm.ObjectTypeCode < 10

Entity Statecode Statecodetext Statuscode Statuscodetext Isdefault
Contact 0 Active 1 Active 1
Contact 1 Inactive 2 Inactive 1
Opportunity 0 Open 1 In Progres 1
Opportunity 0 Open 2 On Hold 0
Opportunity 1 Won 3 Won 1
Opportunity 2 Lost 4 Canceled 1
Opportunity 2 Lost 5 Out-Sold 0
Account 0 Active 1 Active 1
Account 1 Inactive 2 Inactive 1
Lead 0 Open 1 New 1
Lead 0 Open 2 Contacted 0
Lead 1 Qualified 3 Qualified 1
Lead 2 Disqualifi 4 Lost 1
Lead 2 Disqualifi 5 Cannot Con 0
Lead 2 Disqualifi 6 No Longer 0
Lead 2 Disqualifi 7 Canceled 0

In this example, the opportunity statecode ‘lost’ has 2 possible statuscodes, namely ‘canceled’ and ‘out-sold’. Of course, the where statement just limits the amount of lines. You will get the idea.

You can derive this list also for your custom entities. Usually, I generate jsoncode via select to use the selected values in my scripts.

 

,

No comments yet.

Leave a Reply