web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    You are registering a command but are you attaching it to the ribbon button?

    What you probably need to do, instead, is to use existing system command id there to override it (don't have the id off the top of my head.. try using ribbon workbench, btw). I mean this line:

    <CommandDefinition Id="Override.Account.SavePrimary">

  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    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

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

  • Community Member Profile Picture
    on at

    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?

  • ScottDurow Profile Picture
    21 on at

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

  • Community Member Profile Picture
    on at

    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.

  • ashlega Profile Picture
    34,477 on at

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

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    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;


  • Community Member Profile Picture
    on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans