Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Gotcha on checking steps of BPFs

Posted on by 3,079

Found an interesting gotcha today when trying to do some Business Process Flow scripting, and I didn't see it written about anywhere, so thought I'd throw it out here.

Let's say you use javascript to get the active stage, and then the step collection (using code similar to this - https://neilparkhurst.com/2015/11/01/crm-business-processes-and-javascript/).  When you iterate, you may run into issues with some steps being "undefined".  It looks like with the added ability of attaching workflows to stage changes, those now get returned in a call to stage.getSteps, but return as undefined.  So let's say you have 3 fields as steps in your stage, and then 2 workflows set to go on stage exit.  When you call stage.getSteps, your collection length will be returned as 5.  3 will be your 3 fields, and the other 2 will be undefined.  So when you're iterating, you just have to add in a check for undefined before trying to get the name or any properties of the step, otherwise the js will throw an error.

*This post is locked for comments

  • Verified answer
    awalters Profile Picture
    awalters 3,079 on at
    RE: Gotcha on checking steps of BPFs

    Hmmm...can't find a way to mark this as not a question, or an answered question without putting a comment and marking it as the answer.  So that's what this comment is for.  :-)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans