Milos Nikolic Milos Nikolic - 10 months ago 83
Javascript Question

Override MARK COMPLETE ribbon button for custom activity

I need to override MARK COMPLETE ribbon button for custom activity i made.

There is a field that needs to be populated for activity to be completed.

I have to check weather field is populated and complete activity if so.

I have a plan to write JS function to check the field and complete activity, and apply this function to the ribbon button using RIBBON WORKBENCH.

I have two questions:
-Is there any JS command that completes activity?
-If i add this function to ribbon button, will it override default 'complete' function, or I need to disable this function somehow?

Feel free to tell if i need to elaborate this questions more.

Answer Source

I wouldn't override the default behavior, you will end up with an out of the box button which will most probably be reverted back to the way it was when a CU is applied or when CRM is upgraded.

Mark as complete triggers an OnSave, leveraging this fact, why don't you on OnSave look for the save mode value? Save Mode 58 on activities are Save as Completed and perform your tasks?

function onSave(executionContext) {
    var eventArgs = executionContext.getEventArgs();
    var saveMode = eventArgs.getSaveMode();
    if (saveMode === 58) { //Mark as complete
        //do something

        //checks failed,don't want the user to mark as complete?
        return false;