Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Auto choose opportunity form for new opportunities in sales hub

(0) ShareShare
ReportReport
Posted on by Most Valuable Professional

Is there any javascript anyone has that I can use in the onload event of forms to 

- check the app in use i.e. Sales Hub or Project Operations

- If application is Sales Hub, and the opportunity is 'new' / being created, 

Then

Set the form to 'Opportunity'.

Thank you in advance

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Auto choose opportunity form for new opportunities in sales hub

    Hi Lewis Baybutt,

    You have two things to check:

    1. The current app is Sales Hub or not.

    2.The Opportunity is new or not.

    For the first thing, it is easy to do. There is a Client API named getCurrentAppName can do this.

    Code:

    function onload(executionContext){
        var globalContext = Xrm.Utility.getGlobalContext();
        globalContext.getCurrentAppName().then(
        function success(result){
            console.log(result);
        },
        function(error){
            consoe.log(error.message)
        }
        );
    }

    For the second, it shouldn't be triggered when the form is load. It should be triggered when you click the 'New' button, correct?

    pastedimage1656057941054v1.png

    If so, you need to override the New button's command by Ribbon Workbench.

    Please refer to this blog:

    How to override out of the box button’s behavior in ms crm – Dynamics 365 CE/Power Platform, PowerApps, Power Automate, Azure by Vishal Grade

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans