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 :
Customer experience | Sales, Customer Insights,...
Answered

Calling Create New Invoice Javascript Function

(0) ShareShare
ReportReport
Posted on by 129

The client I am working with have a requirement to close an order and at the same time create an Invoice entity record and also a contract record which is a custom entity. 

I have written some JavaScript that creates the new contract and that works well. I was wanting to use the built in JavaScript call that the "Create Invoice" button uses to create the invoice. I have hidden the "Create Invoice" button with RibbonWorkbench and created a new button that calls my custom JavaScript and also the create invoice JavaScript. The issue is I would like to have a "Are you sure" dialog that the user has to confirm before this happens. I can't seem to do this in RibbonWorkbench. Also the create invoice JavaScript file is not available to put on the form so I can't call it from my custom JavaScript. 

Does anybody have a view on how I can achieve only calling the create invoice JavaScript if the user confirms the request?

TIA

Jon

I have the same question (0)
  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    Here are answers to your both questions:

    • Confirmation Dialog: in your JavaScript command (function) you can use Xrm.Navigation.openConfirmDialog to take user consent before converting the order.
    • Use Built-in Fulfil Order/Create Invoice function: you can directly call Sales.SalesOrderRibbonActions.Instance.FulfillOrder in your JS function and there is no need to add the library to the form, The $webresource:Sales/_static/sfa/salesorder/SalesOrderRibbonActions.js is already part of the order form.

    To clarify further, I would do following steps to achieve this functionality:

    • Hide Fulfil Order/Create Invoice button (do not remove, just hide).
    • Add my custom button on the ribbon.
    • Add a command for my button and add a JavaScript action.

    Here is the sample JS Code to launch confirm dialogue and call built-in convert order function:

    function convertOrder_custom() {
    
    var confirmStrings = { text:"Are you sure you want to create invoice?", title:"Confirmation Dialog" };
    var confirmOptions = { height: 200, width: 450 };
    Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
    
    function (success) {    
        if (success.confirmed) {
        
            console.log("Dialog closed using OK button.");
            
            // Cal function to create contract
            
            // Call function to convert order
            Sales.SalesOrderRibbonActions.Instance.FulfillOrder();
    
        }
        else
            console.log("Dialog closed using Cancel button or X.");
    });
    
    
    }

    Here is a screen shot of Ribbon Workbench for your reference:

    pastedimage1609757259937v1.png

    And here is the result:

    pastedimage1609757295137v2.png

    When user click's OK, we get following Built-in Fulfil Order dialogue:

    pastedimage1609757364950v5.png

    You can always, click on customize button command to get the JS function name of a built-in button.

    Let me know if you need further clarification.

    Best,

    Wahaj

    (if this helps, please mark this answer as verified)

  • Verified answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi ,

    You can call OOB JS function inside your custom button js function. Please refer below url for more details:

    pravinpawarweb.wordpress.com/.../

    To show confirmation alert on button:

    pravinpawarweb.wordpress.com/.../

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans