Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

associate js with add new case button

Posted on by Microsoft Employee

Hello, when I open a case and select the Children left nav area, an "Add New Case" button displays on the ribbon. In RWB, this button is displayed in the ribbon as "Add New {0}."

I associated a js command with this ribbon button in RWB. However, the js function doesn't get called. Instead, clicking the button triggers the normal case open functionality and bypasses the custom js command.

Did I wire up this js incorrectly? Or am I misunderstanding the relationship of this button or its ability to support a custom js command?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: associate js with add new case button

    "When you customise commands, a copy of the command is created in your solution."

    Not exactly sure what you mean by this. RWB prompts me to select a solution after I double-click RWB so I select my Case solution which has my Case entity and related objects. In what way is "a copy of the command created in my solution"?  Are you saying that a copy of the command is created in my Case solution?  If so, then is this exposed through the standard solution view?  Or are you referring to local in-memory RWB changes as a solution?

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: associate js with add new case button

    Hi Andrew,

    When you customise commands, a copy of the command is created in your solution. You can then change that command (provided you keep the ID the same) by adding new enable rules or even change the JavaScript function that it is calling. Any uncustomised buttons that use the command will then use your new customised version of the command rather than the core version.

    Hope this helps,

    Scott

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: associate js with add new case button

    Hi Scott - Thanks for your time and expertise. I'm still not clear on how or where I would associate a custom enable rule.  

    Sounds like you're saying I could associate a custom enable rule to use in parallel to the standard CommandCore. However, I think I can only associate an enable rule through a custom command.

    Since custom commands don't get persisted in "customize command" mode then I don't see how I'll be able to successfully associate an enable rule to the button using this method?

  • Verified answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: associate js with add new case button

    Hi Andrew,

    When you use Customise Command then no changes you make to the button will be persisted - so it sounds like what you are seeing is expected.

    If you want to change the button's appearance (e.g. text/images/position) then you use Customise Button, but if you want to change what happens when you use the button you use customise Command. The only exception is when you want to re-wire a button to a different command all together, then you use Customise Button and select a custom command that you have added to your solution.

    The Custom Enable Approach would be good because then you wouldn't need to change the javascript of the command - only add a new enable rule. In this scenario you would customise the command and add an enable rule.

    If you did want to create a custom command, then you could always manually call the javascript function that the core command uses, but you would have to ensure that the same parameters are passed. In this scenario you would have to use Customise Button and point it at a new custom command.

    Hope this helps,

    Scott

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: associate js with add new case button

    Thanks Scott. If I select "Customize Button" then RWB persists the Command that I select/associate.  However, with this approach, the js function is called but the CommandCore is not called. Seems like there should be a way to call CommandCore from the associated Command js. Do you know of any way to do this?

    Your idea of "Customize Command" to associate a custom enable rule sounds interesting. However, when I choose "Customize Command" from the button context menu and select/associate a command, the command I select does not get persisted. For example, if I close and then reopen RWB, the command I selected is no longer selected.  The standard CommandCore is always displayed but I'm not sure how to associate a custom enable rule with this?

    Does it sound like I'm experiencing weird behavior with "Customize Command" or is it more likely that I'm missing/skipping a step that is preventing the "Customize command" command from getting persisted as expected?

  • Verified answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: associate js with add new case button

    Hi Andrew,

    Perhaps the best way would be to customise the command and then add a Custom Javascript Enable Rule to the command so that the button is not enabled when it cannot be used?

    Scott

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: associate js with add new case button

    Hi Scott, my scenario is that when the user clicks the Add New Case button, I want my custom js function to be triggered.  This custom js function will determine if the requested action would have the end result of adding a child to a child and then prevent that action if the condition is true.  If the condition is false then the logic should flow through to the default action/command of the button.  Can you please describe how I would do this in RWB?

  • Verified answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: associate js with add new case button

    Hi Andrew,

    It could be that you are customising the command, but changing the button. If you customise the command, you need to locate the Mscrm.AddNewRecordFromSubGridStandard command and change only that element without changing the ID of the command. If you want to change the command that the button is pointed to then you need to customise the button and not the command.

    Hope this helps,

    Scott

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: associate js with add new case button

    Hi Scott - I selected the button "Add New {0}" from the incident subgrid. This has an ID value of:

    Mscrm.SubGrid.incident.AddNewStandard

    and a CommandCore value of:

    Mscrm.AddNewRecordFromSubGridStandard

    I executed the following steps:

    1. I right-clicked the button and selected "Customize Command."

    2. I changed the Command value to my own custom command value.

    3. I clicked the "Publish Solution" button which completed successfully. Then I closed RWB.

    4. I re-opened RWB and the changes that I made were gone.

    Can you think of a reason why this would happen?  Can you recommend a solution or workaround for this?

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: associate js with add new case button

    Hi Andrew,

    You will need to 'customise command' and change command function called - you might have the wrong button - you need to select the 'SubGrid' ribbon button that has the command 'Mscrm.AddNewRecordFromSubGridStandard'

    Hope this helps,

    Scott

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans