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 :
Microsoft Dynamics CRM (Archived)

Start dialog from javascript when new entity is creating and pass data to the response

(0) ShareShare
ReportReport
Posted on by 360

I have a dialog process. As I know I can start dialog only when one of record selected. Besides I try to run dialog from javascript and if I open one of record it works fine. here is my javascript code snippet

var url = "http://"+ window.location.host + parent.Xrm.Page.context.prependOrgName("/cs/dialog/rundialog.aspx?DialogId={" + dialogId +"}&EntityName=" + entityName + "&ObjectId=" + entityId);

url = encodeURI(url);
window.open(url);

but if I try to open dialog from javascript when a new record is being creating, I have an error "Dialog warning". Can I start dialog when creating a new record?

And how can I pass a value from javascript to dialog response?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jlattimer Profile Picture
    24,562 on at

    I'm not sure you'll be able to do this like you are planning. When you are first creating a record - you haven't actually saved it yet and have not generated the ID for the record. I could see when you would get an error because in your code - entityId should be null if you are launching prior to saving the record.

    You won't be able to send a value from JavaScript to the Dialog - there isn't any supported mechanism to handle this.

  • Sergey Dorofeev Profile Picture
    360 on at

    OK, that's clear. But probably you know any plugin which could help me?

  • Suggested answer
    Community Member Profile Picture
    on at

    Stumbled across this while I was working on something similar and thought I'd share my findings. In my case, I was wanting to run a dialog triggered by an onChange event for a non-required field in the form. I knew some of my users would not save before changing that field so I added a save function and a timeout function for the dialog after the save event. Here's an example of my code. For this to work, you still would need the users to fill out all required fields before triggering the event. I have a business rule to lock the trigger field until all required fields are filled out.

    If you have required fields that may not be filled out at the time you want the dialog to open, then this method will not answer your question unfortunately. In my case, the dialog was to create a different type of record so it was fine to force my users to fill out as much information as needed on the current form. The only shot you'd have if users are not filling information out ahead of time would be to plug in temporary values into all required fields, save the record, run the dialog, and at some point have your users update the information in that form that is filled with temp values.

    function runDialog(){

    var dialogID = "dialogGUID";

    var entityName = "new_entityName";

    if(Xrm.Page.getAttribute("new_requiredField").getValue() != null && Xrm.Page.getAttribute("new_otherRequiredField").getValue() != null) {

    Xrm.Page.data.entity.save();

    var time = 2000;

    setTimeout(

    function () {

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

    var url = Xrm.Page.context.getClientUrl() + "/cs/dialog/rundialog.aspx?DialogId=%7b" + dialogID + "%7d&EntityName=" + entityName + "&ObjectId=" + objectID;

    window.open(url,"","height=600,width=600");

    },

    time

    );

    }

    }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans