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)

Javascript not Trigerring on change event in my Lookup

(0) ShareShare
ReportReport
Posted on by

I  have two entity,one of my entity triggered my java script, the other entity doesn't trigger it. They have both same fields(same name). I insert the js code in the on change event of lookup field(both). I already checked the name but they both the same. So I try to erase some code to test if an error message will occur but nothing happen.Do you think what is the problem?

here is my code it's working fine in the other entity

function makeRequest(method, url) {
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        xhr.setRequestHeader("OData-MaxVersion", "4.0");
        xhr.setRequestHeader("OData-Version", "4.0");
        xhr.setRequestHeader("Accept", "application/json");
        xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        xhr.onload = function () {
            if (this.status >= 200 && this.status < 300) {

                resolve(xhr.response);
            } else {
                reject({
                    status: this.status,
                    statusText: xhr.statusText
                });
            }
        };
        xhr.onerror = function () {
            reject({
                status: this.status,
                statusText: xhr.statusText
            });
        };
        xhr.send();
    });
}
function setExpenseCategorybasedonVendor() {
	if(Xrm.Page.getAttribute("cse_vendor_name") && Xrm.Page.getAttribute("cse_vendor_name").getValue()){
    var lookup1 = Xrm.Page.getAttribute("cse_vendor_name").getValue()[0].id;
    var clientUrl = Xrm.Page.context.getClientUrl();
    var query = clientUrl + "/api/data/v8.0/cse_vendormasters(" + lookup1.slice(1, -1) + ")?$select=_cse_expense_category_value";
    makeRequest('GET', query)
    .then(function (res) {
    var res2 = JSON.parse(res);
    var guid = res2._cse_expense_category_value;
    var query2 = clientUrl + "/api/data/v8.0/cse_expensemasters(" + guid + ")?$select=cse_name,cse_expensemasterid";
    makeRequest('GET', query2)
    .then(function (response) {
    var res3 = JSON.parse(response);
    var value = new Array();
    value[0] = new Object();
    value[0].id = res3.cse_expensemasterid;
    value[0].name = res3.cse_name;
    value[0].entityType = "cse_expensemasters";


if (lookup1 != null){
    
    Xrm.Page.getAttribute("cse_expense_category").setValue(value);
    Xrm.Page.getControl("cse_expense_category").setFocus();     
    Xrm.Page.getControl("cse_amount").setFocus();
     
    }

else{
   Xrm.Page.getAttribute("cse_expense_category").setValue(null);
   Xrm.Page.getElementById("cse_expense_category").clear();
  
}
   
    })
    .catch(function (err) {
    console.error('there was an error!', err.statusText);
    });
    })
    .catch(function (err) {
    console.error(' there was an error!', err.statusText);
    });
	}
    }


*This post is locked for comments

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

    Did you register the OnChange event on the entity form that doesn't work?

    Did you publish?

    Did you enter the function name correctly?

    Are you viewing the correct form when you are testing?

    Did you insert a debugger statement and check if it gets hit with the browser developer tools?

  • Verified answer
    Community Member Profile Picture
    on at

    Please use simple code to check if the onchange event is triggering. Please put below code onchange event of lookup and see if the alert comes up on changing the lookup field value.

    function setExpenseCategorybasedonVendor() {

    alert("Triggered");

    }

  • Community Member Profile Picture
    on at

    Hi Jason,

    Yes , I l aready register it in the onchange, already publish,I already triple checked the function name, I'm viewing the correct form

  • Community Member Profile Picture
    on at

    Hi Mohd,

    I triggered the Message box, but the other function is not trigerring

  • Community Member Profile Picture
    on at

    Thanks for the help, I already know the answer

  • Community Member Profile Picture
    on at

    Please Close he ticket by marking it verified

  • EmployeeOcta Profile Picture
    6 on at

    Hello HeySoul ,

    what was the answer write it here .

    for another people also.

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