Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Open Invoice from opportunity

Posted on by 760

Hi,

I want to skip the order I'm trying to create a button in opportunity that opens invoice form but the id of opportunity shoulde be passed in the invoice but I have no luck.here's my cript

function bill()
{
var test = Xrm.Page.getAttribute('opportunityid');
alert(test);
parameters["opportunityid"] = test;
Xrm.Utility.openEntityForm("account", null, parameters);
}

*This post is locked for comments

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Open Invoice from opportunity

    Glad it worked.

    You can read more about openEntityForm here-

    msdn.microsoft.com/.../gg328483.aspx

    msdn.microsoft.com/.../jj602956.aspx

    msdn.microsoft.com/.../gg334375.aspx

  • CRMexplorer Profile Picture
    CRMexplorer 760 on at
    RE: Open Invoice from opportunity

    Thank you so much! it worked :) I 'll just study the code thank you

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Open Invoice from opportunity

    Hi Jane,

    This is not working because customerid field is of type customer which can accept account or contact record. So while setting the id, you also need to set the type of record.

    try this code

    ==============

    if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {

           parameters["customerid"]  = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;

           parameters["customeridname"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;

           parameters["customeridtype"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;

       }

    ===============

    Complete code:

    ==================

    function bill() {

       var parameters = {};

       var OpportunityId = Xrm.Page.data.entity.getId();

       var OpportunityName = Xrm.Page.data.entity.attributes.get("name").getValue();

       parameters["opportunityid"] = OpportunityId;

       parameters["opportunityidname"] = OpportunityName;

       if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {

           parameters["customerid"]  = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;

           parameters["customeridname"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;

           parameters["customeridtype"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;

       }

       var windowOptions = {

           openInNewWindow: true

       };

       Xrm.Utility.openEntityForm("invoice", null, parameters, windowOptions);

    }

    ===========================

    I hope this helps. If my post answers your question, please mark as "Verified"

  • Suggested answer
    Jagannath Profile Picture
    Jagannath 545 on at
    RE: Open Invoice from opportunity

    Hi jane,

    var name=Xrm.Page.getAttribute("name").getValue();//logical name of the customer

    parameters["name"] = name;

    in ur code u r passing customerid instead of customer name.

    check the logical name of customer and pass as the above.

    Thanks,

    jagannath

  • CRMexplorer Profile Picture
    CRMexplorer 760 on at
    RE: Open Invoice from opportunity

    Hi Ravi,

    the code works but I also want to passed the customer name can you help me understand why this code is not working I only added the customer id

    var s=Xrm.Page.getAttribute('customerid').getValue();

    parameters["opportunityid"] = id;

    parameters["customerid"]=s;

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Open Invoice from opportunity

    Hi Jane,

    You need to add a ribbon button and call the below JS code to open the invoice record from opportunity.

    ############################

    function bill()

    {

    var parameters = {};

    var id = Xrm.Page.data.entity.getId();

    parameters["opportunityid"] = id;

    var windowOptions = {

    openInNewWindow: true

    };

    Xrm.Utility.openEntityForm("invoice", null, parameters, windowOptions );

    }

    ############################

    Though the above code will work but I believe you can achieve this requirement with a no code appproach as well i.e. just adding a subgrid (All invoices) on the Opportunity form and then CRM itslef will open the invoice form pre populating the opportunity when you click the '+' on the subgrid.

    I would recommend this approach if there are no business reasons to use the above JS code.

    Hope this helps.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Open Invoice from opportunity

    Hi,

    Please refer to the article below

    msdn.microsoft.com/.../jj602956.aspx

    i was wondering something because you said you want to open the invoice form but the parameter that you passing is account.


    var parameters = {}; is missing 

    Kindly change the

    Xrm.Utility.openEntityForm("account", null, parameters); 

    To

    Xrm.Utility.openEntityForm("invoice", null, parameters); please get the schema name from your customization.

    var test = Xrm.Page.getAttribute('opportunityid');

    to

    Xrm.Page.data.entity.getId()

    Final Code

    function bill()
    {

    var parameters = {};
    var test = Xrm.Page.data.entity.getId();

    alert(test);
    parameters["opportunityid"] = test;
    Xrm.Utility.openEntityForm("invoice", null, parameters);

    }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans