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)

JScript alert raised twice in CRM form

(0) ShareShare
ReportReport
Posted on by

I have a JScript routine to check for duplicate ID which is activated upon ID field onChange event. The routine works.  However, if duplicate ID is detected, the JScript alert statement is raised twice.

Under IE 11
The first alert popup said Duplicate ID detected
The second alert popup said Duplicate ID detected (repeat).

Under Chrome version 43.0.2357.130

The first alert popup said Duplicate ID detected.
The second alert popup said Duplicate ID detected, followed by a checkbox, (to tick) to prevent this page from creating additional dialog.

How to solve this issue?

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Share you code here for inquiry

  • Community Member Profile Picture
    on at

    function IDFieldOnChange() {

    var id = Xrm.Page.getAttribute("vc_id").getValue().trim();
    var Result = checkDigit(id);
    if (Result == true) {

    id = id.toUpperCase();
    Xrm.Page.getAttribute("vc_id").setValue(id);

    // Check for Duplicate in vc_direct_access_list

    try {

    var ClientURL = window.parent.Xrm.Page.context.getClientUrl();
    var ODataPath = ClientURL + "/XRMServices/2011/OrganizationData.svc";
    var ODataRequest = new XMLHttpRequest();
    ODataRequest.open("GET", ODataPath + "/vc_direct_access_listSet?$top=1&$filter=vc_id eq '" + id + "'", false);

    ODataRequest.setRequestHeader("Accept", "application/json");
    ODataRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    ODataRequest.send();

    if (ODataRequest.readyState == 4 /* complete */) {

    if (ODataRequest.status === 200) {

    block_records = this.JSON.parse(ODataRequest.responseText).d;
    var dal = block_records.results;
    if (dal[0] != null) {
    alert("Duplicate ID detected");
    Xrm.Page.getAttribute("vc_id").setValue(null);
    Xrm.Page.getControl("vc_id").setFocus();
    return false;
    }

    }
    else {
    alert("Error " + ODataRequest.status);
    }
    }
    } catch (err)
    { alert(err.message); }

    }
    else {
    Xrm.Page.getAttribute("vc_id").setValue(null);
    alert("Wrong NRIC/FIN format");
    Xrm.Page.getControl("vc_id").setFocus();
    }
    }

  • Verified answer
    HenriL Profile Picture
    485 on at

    Hi Tiong,

    Few observations:

    a. Dont need a trim() as Dynamics form automatically trim any leading/trailing spaces.

    b. You re-assigned the uppercased ID back to the same field. This might have triggered the second onChange event.

    Btw, check out XrmServiceToolkit in Codeplex. Simplify and make your code easier to read instead of writing those HTTP header lines.

    Hope that helps.

    Henri

  • Mahendar Pal Profile Picture
    45,095 on at

    Could you also share how you are calling event details

  • Community Member Profile Picture
    on at

    Hi Henri,

    Thank you for your advice.  The re-assigned uppercased ID is not the issue.  The second line after the alert statement,

    Xrm.Page.getAttribute("vc_id").setValue(null);

    causes the repeated alert.  It is to force user to re-enter another ID.

    How to overcome this?  Also, the third line to setFocus on the ID control does not work as well.

    Tiong

  • Verified answer
    HenriL Profile Picture
    485 on at

    Hi Tiong,

    I would replace the alert statement with getControl('fieldname').setNotification('message') function. It is much cleaner and better user experience. Basically, any field with notification will prevent user from saving the record unless the notification is cleared (simply by calling setNotification with empty message).

    That way you don't need setFocus anymore. Also, I wouldn't worry about setting the field value to null. Just let the user to re-enter the value.

    Sorry that I can't test and give you proper code as I am on my way home.

    Regards,

    Henri

  • Community Member Profile Picture
    on at

    It works now with the Notification.

    I also found out that I need the trim as CRM form only trim the display portion, but internally it is not trimmed.

    Thank you.

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