Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM JavaScript action prior to OOB command on Ribbon button

(0) ShareShare
ReportReport
Posted on by

I have seen many posts regarding this issue.

1. That this is not supported

2. That some have gotten it to work

I have tried this with no success. The system function I was trying to call, takes a CRM Parameter (Primary Control).

I guess the question is what is the alternative, if this functionality is not supported?

The useful scenario is to add a 'JS Confirm' functionality before the system action is executed.

Here is the Command Definition:

<CommandDefinition Id="Override.Account.SavePrimary">
      <EnableRules>
        <EnableRule Id="Mscrm.AvailableOnForm" />
        <EnableRule Id="Mscrm.CanSavePrimary" />
        <EnableRule Id="Mscrm.ReadPrimaryPermission" />
        <EnableRule Id="Mscrm.IsAutoSaveDisable" />
      </EnableRules>
      <DisplayRules>
        <DisplayRule Id="Mscrm.CanSavePrimaryEntityType" />
      </DisplayRules>
      <Actions>
        <JavaScriptFunction FunctionName="testsave" Library="$webresource:newab_testscirpt">
          <CrmParameter Value="PrimaryControl" />
        </JavaScriptFunction>
      </Actions>
    </CommandDefinition>

And the JS:

function testsave(PrimayControl) {
    if (confirm("Are you sure?"))
        Mscrm.RibbonActions.saveForm(PrimayControl);
 }

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    scratch my last post. I can apply your suggestion to the 'Submit Order' scenario as well.

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    Alex, I'll give this shot. looks promising. The reason I wanted to do this through the button action was that on a separate project, I need to tie this sort of functionality to the 'Submit Order' button, which does not have a unique Save Action status. That's why I had to tied it to the button itself.

  • Verified answer
    ashlega Profile Picture
    34,477 on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    This would be a purely unsupported nonsense (we are not supposed to do these things), but, if you just added the script below as a web resource to your form (no need for the ribbon buttons/handlers), it would work. It's relatively harmless from the upgrade standpoint and can be easily removed.

    var originalSaveForm = window.parent.Mscrm.RibbonActions.saveForm;
    var inSave = false;
    function overridenSaveForm(param)
    {
       if (!inSave)
       {
            inSave = true;
            try
            {
               if(confirm("Are you sure?"))
                  originalSaveForm(param); 
            }
            finally
            {
               inSave = false;
            }
       }
    }
    window.parent.Mscrm.RibbonActions.saveForm = overridenSaveForm;


  • ashlega Profile Picture
    34,477 on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    "delete post" does not work - see correct one below.

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    I don't want to re-write the ProcessOrder functionality. I merely want to make a few validations, when the user clicks the 'Submit Order' button and if passed, call the OOB ProcessOrder function.

  • ScottDurow Profile Picture
    19 on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    You would need to implement your own custom server side process to do this and call from JavaScript.

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    Scott,

    And what if I am overriding the 'Submit Order' which calls the Mscrm.SalesOrder.ProcessOrder() JS functionality? What would be the equivalent of that in Xrm.Page.entity object model?

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    Do  Xrm.Page.entity.save and Mscrm.RibbonActions.saveForm(PrimayControl) offer the same functionality?

  • Suggested answer
    ScottDurow Profile Picture
    19 on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    Hi

    It isn't supported to call OOTB ribbon functions in this way - you will need to use the Xrm.Page.entity.save - msdn.microsoft.com/.../gg334720.aspx

    Hope this helps

  • Community Member Profile Picture
    on at
    RE: CRM JavaScript action prior to OOB command on Ribbon button

    I cloned the OOB button and attached the command to the new button (using workbench). I have tested this with other commands that do not pass a parameter to the script, and it works fine. It is only when there is a parameter being passed to the script, that the standard call doesn't get executed. I do get the 'Confirm' prompt.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,157 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,930 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans