Tip #655: Defensive use of undocumented functions

Black boxThis is a sweet lesson for all the lovers of the undocumented functions. On odd occasion yours truly is guilty of being lazy and choosing a shortcut worthy spießrutenlaufen. From time to time those fits of laziness come back hard.

For a long time I’ve been using SaveAsCompleted internal function on a command bar for custom activities. For whatever reason the function is no longer present in CRM 2015 Update 1.1 and above. My short-term fix? Bury myself even deeper in the undocumented internal land:

if(typeof(SaveAsCompleted) == "function")
   SaveAsCompleted();
else if(typeof(Mscrm.CommandBarActions.saveAsCompleted) 
        == "function")
   Mscrm.CommandBarActions.saveAsCompleted();
else {
   // do whatever had to be done in a first place
}

Lesson: if you are going to use internal functions, at least do it defensively.

2 thoughts on “Tip #655: Defensive use of undocumented functions

  1. Joe Newstrom says:

    Don’t forget
    try { } catch (e) { }

    !!!

    Any time something is reasonably likely to fail in the future, you’re best off controlling the failure mode in advance.

    Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *