1

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?

enter image description here

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

Thanks

Yogeshree Koyani
  • 1,649
  • 10
  • 19
AndroidAL
  • 1,111
  • 4
  • 15
  • 35
  • 2
    where you get value of parent, getvalue(); has incorrect case. (should be get**V**alue()) – MarioZG Oct 07 '15 at 17:40
  • Best way to work this out is the just step through the code and debug. – James Wood Oct 08 '15 at 07:56
  • Its also possible that your function is being called incorrectly or is not being instantiated properly. All the error is saying is that there is an error with one of your onsave event functions. – Joseph Duty Oct 09 '15 at 19:19

1 Answers1

1

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

Mitch Gollub
  • 432
  • 4
  • 5