Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Unable to clear the value of a lookup field- using Java Script

$
0
0

Hi I read many article about clearing a field and tried them but, they are not running.
I tried this code, but nothing happen.

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

my full code;

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";


	Xrm.Page.getAttribute("cse_expense_category").setValue(value);
	Xrm.Page.getControl("cse_expense_category").setFocus();
    Xrm.Page.getControl("cse_amount").setFocus();
    Xrm.Page.getControl("cse_expense_category").setFocus();
	Xrm.Page.getControl("cse_memo").setFocus();

    if (lookup1 = null){

       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);
    });
	}
    }



Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images