Hi M-Files community,
As I often come to temptation/requirement to make specific business logic based on workflow state transition, I would like to start discussion with you about best practice to compare specific workflow state transitions with a current one.
I have a concrete use case where I have a single "Reject" workflow state but multiple workflow transitions going into that workflow state (basically users can reject it from different workflow states). Based on previous workflow state or workflow state transition, I would need to apply different logic (in my case reset different comments properties in specific document).
What ever I try, I end up comparing names of workflow state transitions or comparing names of workflow states.
Here some options what I can get:
// 1st Approach // Get current "State transition" but only getting the name // Here actually I do not get "State transition" at all, I suppose it is not attached to object, I get NULL var propertyValue = env.PropertyValues.SearchForPropertyByAlias(env.Vault, "State transition", true); var myCurrentStateTransition = propertyValue.TypedValue.DisplayValue; // Getting workflow state transition ID by alias (we tend to use alias as they are more stable than IDs) var mySpecificStateTransitionId = env.Vault.WorkflowOperations.GetWorkflowStateTransitionIDByAlias("<MY SPECIFIC WORKFLOW STATE TRANSITION>"); // Then compare // PROBLEM: One one side I have name on the other side Id!? // 2nd Approach // Comparing workflow states // Get all workflow states in descending order var objVersions = env.Vault.ObjectOperations.GetHistoryEx(env.ObjVer.ObjID, MFHistoryRetrievalMode.MFHistoryRetrievalDescending); // Get workflow state from previous version objVersions.ObjVer var previousWorkflowState = env.Vault.ObjectPropertyOperations.GetProperty(objVersions.ObjVer, Constants.WORKFLOW_STATE); // Compare // PROBLEM: I can get workflow state id by alias, guid but I can not get the current name // Actually I would like to compare aliases from previous state and specific state if(previousWorkflowState.TypedValue.DisplayName == "<some hardcoded workflow state>")
2nd Approach works generally but has a problem that I need to search through history for previous workflow state (still ok I guess) but I need to hard-coded name of workflow state I would expect. It would be very good if I could compare alias from previous state with alias from specific state. Names and Ids can easily change, also very often we tend to use the same names (also additional problem with duplicated names but ok this is our problem) where this logic would not work. Also names can be easily change without thinking about consequences (some user wish another name, we change it and suddenly the business logic does not work any more).
This is why I think comparing aliases would be the best solution as they are usually treated more serious as another values.
I am wondering why PropertyValue does not have alias info:
-> Alias (currently missing)
I think this could really help with these kind of comparisons and would make them more stable and secure.
What do you think about that idea?
Do you use different technique for this kind of comparisons? I would be glad to hear about your experiences.