Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

JavaScript in OnChange event is not safe

(0) ShareShare
ReportReport
Posted on by

Hi everybody!!

I wrote a JavaScript to launch a new window of entity related when the optionset is selected.

There is the code:

function PushLoa() {
    var tema = Xrm.Page.getAttribute("name").getValue();
    var GUID = Xrm.Page.data.entity.getId()
    var entitytype = "opportunity";
    var lookupdata = new Array;
    var lookupitem = new Object;
    lookupitem.id = GUID;
    lookupitem.name = tema;
    lookupitem.entitytype = "opportunity";
    lookupdata[0] = lookupitem;
    var primaryField = Xrm.Page.data.entity.getPrimaryAttributeValue();
    var windowOptions = { openInNewWindow: true };
    var parameters = {};
    parameters["odm_name"] = "Solicitud para " + tema;
    parameters["odm_oportunidad"] = GUID;
    parameters["odm_oportunidadname"] = primaryField;
       var solicitud = Xrm.Page.getAttribute("odm_solicituddeloas").getText();
    if (solicitud == "Solicitada") {
      
        Xrm.Utility.openEntityForm("odm_loa", null, parameters, windowOptions);
            }
}

It works as follows:

The user change the optionset field from opportunity entity and the system open new window with this new entity. This new window is filled with the name of the record  and with entity related lookup filled (opportunity lookup field). This is OK.

Then user saves and closes the new entity record, and he backs to opportunity entity record. And in  this time, the optionset field is open and user have to click on the screen to validate the selected option. In fact, the user can change the option selected on the first time, without it start again the JavaScript.

The question is Can I close the optionset fields with the option selected?

Thank you in advanced

*This post is locked for comments

  • Suggested answer
    Rahul-Waghmare Profile Picture
    Rahul-Waghmare 990 on at
    RE: JavaScript in OnChange event is not safe

    Tell me one thing, once user select optionset value at that time only new window will be opened, right. Before opening the new window can you write single line to setfocus to another field on the form or the field next to option set.

    Xrm.Page.ui.controls.get("FieldName").setFocus();

    Thanks,

    Rahul

  • JMdeSingular Profile Picture
    JMdeSingular on at
    RE: JavaScript in OnChange event is not safe

    Hi Rahul,

    Firstly, thank to answer.

    Then, How do I make it  possible? How do I try to remove the focus by javascript? Because the user remove the focus when he clicks on anywhere of the screen. But this action isn`t a answer.

    thanks

  • Suggested answer
    Rahul-Waghmare Profile Picture
    Rahul-Waghmare 990 on at
    RE: JavaScript in OnChange event is not safe

    Hi,

    Once you closed the child window try to remove the focus from optionset then it will get closed.

    Regards,

    Rahul

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans