Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Opening the dialog on button click

Posted on by 299

Hi there,

I have added a button to my custom entity so that on the click of that button a dialog should be opened,

The web resource code for the button I have added below:

<html><head><meta charset="utf-8"></head><body><button onclick="openDialogProcess('%7b890D1424-7F35-49F1-9E5A-5A3180A1FA66%7d','new_nameh',objectId)" type="button" ;=""> Click Me!</button> 
</body></html>

I got the dialogId and entityName but the objectID depends on the record that has been selected.

and a javascript in the form properties is:

function openDialogProcess(dialogId,entityName,objectId)
{
var url = Xrm.Page.context.getClientUrl() + "/cs/dialog/rundialog.aspx?DialogId=" +
dialogId +"&EntityName=" +entityName + "&ObjectId=" + objectId;
window.open(url);
}

I haven't set any event or parameters for the javascript.

the problem is when I click on the button nothing happens! and the dialog doesn't open up. any ideas?
 


*This post is locked for comments

  • Suggested answer
    Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: Opening the dialog on button click

    Hi Z.sam,

    Please check the below url :

    www.dynamicsconsulting.de/microsoft-dynamics-crm-2011-how-to-launch-a-dialog-on-click-of-custom-ribbon-button

    Hope it would be helpful !!

  • Suggested answer
    Vahid Samimi Profile Picture
    Vahid Samimi 210 on at
    RE: Opening the dialog on button click

    use this addons for call dialog

    [View:https://processjs.codeplex.com/:750:50]

    Call Dialog

    Note: This function has been deprecated. It will remain in the solution, however no future enhancements or fixes will be done. Please check out Alert.js for a better way of showing dialogs.

    Opens the specified dialog for a particular record in a CRM light-box, or Modal Dialog if run from Outlook. Once the dialog is closed, a custom callback function can be executed, e.g. to refresh the form with new data set by the dialog.

    Parameters: Dialog ID/Guid, Entity Name, Record ID/Guid, Callback function, CRM Base URL (not required on forms/views)

    Usage:

    Process.callDialog("C50B3473-F346-429F-8AC7-17CCB1CA45BC", "contact", 
        Xrm.Page.data.entity.getId(),         
        function () { 
            Xrm.Page.data.refresh(); 
        });



    Note you must add process.js library on form onload
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Opening the dialog on button click

    Hi Sam,

    You can append or insert a button on the form using javascript on Document Ready and then assign your dialog open function to the onClick event.

    Thanks.

  • z.sam Profile Picture
    z.sam 299 on at
    RE: Opening the dialog on button click

    Dear Sandeep Kumar, I wanted to open the dialog on the button click event.

    like this artical

    ribbonworkbench.uservoice.com/.../140652-create-a-dialog-short-cut-ribbon-button

    I want to add my own button inside the form and open the dialog. is it possible?

  • z.sam Profile Picture
    z.sam 299 on at
    RE: Opening the dialog on button click

    Dear Abhishek Kumar, I corrected my code didn't work.

  • z.sam Profile Picture
    z.sam 299 on at
    RE: Opening the dialog on button click

    Dear Goutham,the object Id must be passed on run time, based on the record we select, we got different object ID's.

  • abhishek_255 Profile Picture
    abhishek_255 1,612 on at
    RE: Opening the dialog on button click

    Hi -

    Looks like issue in button tag. Please check your button code

    type="button" ;=""> Click Me!</button> 

    Best Regards,
    Abhishek
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Opening the dialog on button click

    Hi Sam,

    To open up the dialog box on button click, you can use functions given below.

    Just copy and Paste the Javascript Functions in the Javascript Library file like this -

    Open Form Editor:

    1.    Go To “Form Properties” Option.

    2.    A New Form Open, Click Events Tab.

    3.    Click on “Add” button from Event Handler Section. Specify the function name to call on selected event. Click Save.

    4.    Now, click “Edit Library” button from Event Handler Section. Copy and Paste functions given below in the form.

    function runDialog() {
        var dialogID = "F0BC9064-7F1B-4046-AD68-A4CDCSJGDJSJKA";
        var today = new Date();
        var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
        var time = 2000;
        var objId = Xrm.Page.data.entity.getId();
        setTimeout(
         function () {
             window.showModalDialog(serverUri + '?DialogID={' + dialogID + '}&EntityName=lead&ObjectId=' + objId, null, 'width=615,height=480,resizable=1,status=1,scrollbars=1');
         }, time);
    }

    // To Open Quick Create Form
    function OpenFeedbackForm() {
        //lookup object of current lead record
        var parrentLead = {
            entityType: "lead",
            id: Xrm.Page.data.entity.getId()
        };

        var parameters = {
            companyname: Xrm.Page.getAttribute("companyname") != null && Xrm.Page.getAttribute("companyname").getValue() != null ? Xrm.Page.getAttribute("companyname").getValue() : "",
            fullname: Xrm.Page.getAttribute("fullname") != null && Xrm.Page.getAttribute("fullname").getValue() != null ? Xrm.Page.getAttribute("fullname").getValue() : "",
            jobtitle: Xrm.Page.getAttribute("jobtitle") != null && Xrm.Page.getAttribute("jobtitle").getValue() != null ? Xrm.Page.getAttribute("jobtitle").getValue() : "",
            new_agenda: Xrm.Page.getAttribute("new_agenda") != null && Xrm.Page.getAttribute("new_agenda").getValue() != null ? Xrm.Page.getAttribute("new_agenda").getValue() : "",
            ownerid: Xrm.Page.getAttribute("ownerid") != null && Xrm.Page.getAttribute("ownerid").getValue() != null ? Xrm.Page.getAttribute("ownerid").getValue() : "",
            new_smename: Xrm.Page.getAttribute("new_smename") != null && Xrm.Page.getAttribute("new_smename").getValue() != null ? Xrm.Page.getAttribute("new_smename").getValue() : "",
            decisionmaker: Xrm.Page.getAttribute("decisionmaker") != null && Xrm.Page.getAttribute("decisionmaker").getValue() != null ? Xrm.Page.getAttribute("decisionmaker").getValue() : "",
            purchasetimeframe: Xrm.Page.getAttribute("purchasetimeframe") != null && Xrm.Page.getAttribute("purchasetimeframe").getValue() != null ? Xrm.Page.getAttribute("purchasetimeframe").getValue() : ""
        };
        Xrm.Utility.openQuickCreate("Lead", parrentLead, parameters).then(function (lookup) { successCallback(lookup); }, function (error) { errorCallback(error); });
    }

    function successCallback(lookup) {
        alert('succes');
        console.log("lookup: " + lookup.savedEntityReference.id);
    }

    function errorCallback(e) {
        console.log("Error: " + e.errorCode + " " + e.message);
    }

    5.    Click Save and Publish.

    Please mark my answer as verified, if it solve your query.

  • Suggested answer
    Goutham A Profile Picture
    Goutham A on at
    RE: Opening the dialog on button click

    Hi Sam,

    what is the object ID you were passing, it should be entityId/objectID of the custom entity you created(like 112 for case/incident)

    Also, if you button is inside a web resource, you need to use parent.Xrm to access page level XRM methods/properties

    try this: var url = parent.Xrm.Page.context.getClientUrl() + "/cs/dialog/rundialog.aspx?DialogId=" +
    dialogId +"&EntityName=" +entityName + "&ObjectId=" + objectId;

    Please check what error you were thrown by presseing f12(client debugging)


    <<please mark my answer as suggested if it solved your query>>

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans