+ Start a Discussion
Matt FolgerMatt Folger 

Trying to add a ownerID check to this Workflow Rule criteria.

Presently I have this workflow rule logic that checks to see if a certain set of subtasks by a certain department is completed and if so it passes ownership to the next user in the process.  The problem is that is doesn't check who was previous owner and therefore the logic is flawed.  If one of these processes gets further along it'll keep firing, rather than just the 1 time that I goes between departments.

AND( NOT(ISBLANK( TEXT(Competitive_Analysis__c) )) , NOT(ISBLANK(TEXT(Catalog_Item_UDF__c))) , NOT(ISBLANK(TEXT(Market_Driven_Price_UDF__c ))), NOT(ISBLANK( TEXT(Packaging_and_Label_Specifications__c)) ), NOT(ISBLANK( TEXT(Recommendations_for_Stock_Levels__c)) ) , NOT(ISBLANK(TEXT( Replace_Other_Product_and_Obsolescence__c ))), NOT(ISBLANK(TEXT( Requirements_Document__c) )), NOT(ISBLANK(TEXT( Sales_Training_CSA__c ))) , NOT(ISBLANK(TEXT( Sales_Training_RSM__c ))))

User-added image

I've tried to add some "OwnerID" logical operators but it keeps telling me that my users don't exist, their login names, their userIDs, their aliases.  Nothing works.  How would I add a logical check in the above formula to check for existing owner and only fire if it was owned by the previous owner and only if all their tasks were completed.
Best Answer chosen by Matt Folger
kevin Carotherskevin Carothers
Hi-

My suggestion is I think you'll have to write a trigger that saves the previous owner in a custom field so your VR can ge to it -- for example, on an account;

trigger OnAccOwner on Account (before update) {
    for( Account a : Trigger.new ) {
        Account AcctBeforeUpdate = Trigger.oldMap.get( a.Id );

        if( AcctBeforeUpdate.OwnerId != a.OwnerId
                && ((String) a.OwnerId).startsWith( '005' ) )
            a.Previous_Owner__c = AcctBeforeUpdate.OwnerId;
    }
}
...Then you should be able to get to it in a VR;

AND( NOT(ISBLANK( TEXT(Competitive_Analysis__c) )) ,
       NOT(ISBLANK(TEXT(Catalog_Item_UDF__c))) ,
       NOT(ISBLANK(TEXT(Market_Driven_Price_UDF__c ))),
       NOT(ISBLANK( TEXT(Packaging_and_Label_Specifications__c)) ),
       NOT(ISBLANK( TEXT(Recommendations_for_Stock_Levels__c)) ) ,
       NOT(ISBLANK(TEXT( Replace_Other_Product_and_Obsolescence__c ))),
       NOT(ISBLANK(TEXT( Requirements_Document__c) )),
       NOT(ISBLANK(TEXT( Sales_Training_CSA__c ))),
       NOT(Previous_Owner__c = $User.Id),      
       NOT(ISBLANK(TEXT( Sales_Training_RSM__c ))))

BTW- You should add logic for the case of the previous owner being a queue.
Also, you might want to make a before insert trigger to populate the Previous_Owner__c  field of your record.

All Answers

Ramu_SFDCRamu_SFDC
Since the logic is complex, why not consider using Triggers so that you will have complete control of the changes done to each and every field using context variables https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm.

More over there are few limitations in workflows, like you can use ISCHANGED logic only in one evaluation criteria etc..,

Hope thsi helps !!
kevin Carotherskevin Carothers
Hi-

My suggestion is I think you'll have to write a trigger that saves the previous owner in a custom field so your VR can ge to it -- for example, on an account;

trigger OnAccOwner on Account (before update) {
    for( Account a : Trigger.new ) {
        Account AcctBeforeUpdate = Trigger.oldMap.get( a.Id );

        if( AcctBeforeUpdate.OwnerId != a.OwnerId
                && ((String) a.OwnerId).startsWith( '005' ) )
            a.Previous_Owner__c = AcctBeforeUpdate.OwnerId;
    }
}
...Then you should be able to get to it in a VR;

AND( NOT(ISBLANK( TEXT(Competitive_Analysis__c) )) ,
       NOT(ISBLANK(TEXT(Catalog_Item_UDF__c))) ,
       NOT(ISBLANK(TEXT(Market_Driven_Price_UDF__c ))),
       NOT(ISBLANK( TEXT(Packaging_and_Label_Specifications__c)) ),
       NOT(ISBLANK( TEXT(Recommendations_for_Stock_Levels__c)) ) ,
       NOT(ISBLANK(TEXT( Replace_Other_Product_and_Obsolescence__c ))),
       NOT(ISBLANK(TEXT( Requirements_Document__c) )),
       NOT(ISBLANK(TEXT( Sales_Training_CSA__c ))),
       NOT(Previous_Owner__c = $User.Id),      
       NOT(ISBLANK(TEXT( Sales_Training_RSM__c ))))

BTW- You should add logic for the case of the previous owner being a queue.
Also, you might want to make a before insert trigger to populate the Previous_Owner__c  field of your record.
This was selected as the best answer
Matt FolgerMatt Folger

Thanks, I "cheated" and ended up creating some "N+1" logic that I think will actually serve me better as it would be individual independant in case there are some terminations, or staffing changes in the future, I won't have to adjust my app.
 

Thanks for the replies!