1
votes

I am going to prompt a javascript confirmation before doing something by clicking on a ribbon button. For ex, when I am going to click on the send button for email activity I want to prompt a dialog to say "are you sure?" and based on the answer do the main functionality. what is the best way to do such thing in CRM 2011?

3

3 Answers

2
votes

The javascript for such an event could be implemented easily enough using something like:

function confirmSomething(message) {
    if (!confirm(message)) {
        //user has changed their mind 
        event.returnValue = false;
        return false;   //you might need to double check this bit
    }
}

As for adding it to a button - there are plenty of guides for that (Google is your friend - I like this one )

Or perhaps try the Visual Ribbon Editor

0
votes

You can add new javascript web resource. Create function where you will add confirmation dialog. On 'confirm=true' call main CRM functionality. In your example with email, it will be method send from /_static/activities/email.js.

Ofcourse you have to change Action on your Ribbon button to call your function from web resource.

Hope it will help :)

0
votes

well, the best approach is to create on save event and choose to pass execution context as

first parameter and inside the event handler you can stop or continue saving based the result

from the confirmation message.

code sample:

function Form_onsave(executionObj) { var shouldSave = true;

if (shouldSave)
{
    alert("Unable to save because of some reason or the other.");

    executionObj.getEventArgs().preventDefault();
}

}