简体   繁体   中英

Auto-Populate Field using Javascript

I created this javascript to auto populate a field, with values from other fields. It is called in the form onSave event.

function OppTopic() {

var products = "";


var parent = Xrm.Page.getAttribute("parentaccountid").getvalue();
var city = Xrm.Page.getAttribute("address1_city").getValue();
var automation = Xrm.Page.getAttribute("new_automationfeatures").getValue();
var service = Xrm.Page.getAttribute("new_service").getValue();

//Determines if a Product/Service is selected   


if (automation == true) {//***AUTOMATION***
    if (products != ""){
    products += ",Automation";
    }
    else{
    products = "Automation";       
    }
}

if (service == true) {//***SERVICE***

    if (products != "")
        products += ",Service";
    else
        products = "Service";
}

if (automation == false && service == false) {

    products = "null";
}


var subject = parent + " - " + city + " - " + products; 
Xrm.Page.getAttribute("name").setValue(subject);

}

But , when the form is saved this is the error that appears.I'm not really sure what the error means?

在此处输入图片说明

I have checked the field names and they are correct. What could be the problem that is causing this error?

Thanks

var parent will return a javascript object that is a CRM lookup. If you are putting it together in a string with other strings, you will have to retrieve the name or whichever other attribute from the lookup you're trying to add

    var parentName = "";
    var parent = new Array();
    parent = Xrm.Page.getAttribute("parentaccountid").getValue();
    if(parent!=null){ 
        parentName = parent[0].name;
    }

Source: http://www.mscrmconsultant.com/2012/08/get-and-set-lookup-value-using.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM