web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error in field's customization javascript

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm doing this test with Rest and Soap Web Services in CRM online 2013 based in a Video, but in my test I'm getting the error:  "ContactoChange is undefined" when I'm changing the Contact. Any thoughts? Thank you in advance! 

Danitza. 

ContactoChange = function()
{
	var new_name=Xrm.Page.getAttribute("new_name").getValue();
	if (new_name==null) new_name"";
	var contactid=Xrm.Page.getAttribute("new_Contact").getValue();
	if (contactid==null) return;
	
	// Rest 
	
	XrmServiceToolkit.Rest.Retrieve(
	contactid[0].id,
	"ContactSet",
	null, null,
	function (result) {
		var emailaddress1 = result.EMailAddress1 ;
		alert(emailaddress1);
		},
		function (error) {
			equal(true, false, error.message);
		},
		false
	);
	
	//soap
	

	var cols = ["emailaddress1"];
	var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactid[0].id,cols);
	Xrm.Page.getAttribute("new_name").setValue(new_name+ retrievedContact.attributes["emailaddress1"].value);
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at
    RE: Error in field's customization javascript

    It sounds like you have not published the JavaScript webresource containing the script. The error you are seeing is because the onchange event is trying to call the function Contactochange but the script that defines it has not been run.

  • Suggested answer
    Hosk Profile Picture
    on at
    RE: Error in field's customization javascript

    Scott is correct

    You need to add the javascript file to the entity form, this will ensure the javascript file is loaded when the form is loaded.

    You will need to publish changes.

    I guess then you have added an onchange event to a contact lookup but because either you haven't added the javascript file .

    Also watch out for adding an onchange event and then not changing what javascript selected, often the default javascript file isn't the correct one.

  • Verified answer
    Waqar Sohail Profile Picture
    on at
    RE: Error in field's customization javascript

    Hi Dantiza,

    I didn't understand this statement.

      if (new_name==null) new_name"";  if you assigning value.   if (new_name==null) new_name="";

    it causing error which make your javascript Undefine. Please correct it and also clear your browser cache.

  • Community Member Profile Picture
    on at
    RE: Error in field's customization javascript

    Hi Scott, Thank you for your answer! The Web Resource is published, added on the Entity Form and also in the On change event on the Contact Entity.  I think is something in the Code.

  • Community Member Profile Picture
    on at
    RE: Error in field's customization javascript

    Hey Ben! the JS file is loaded in the Entity Form and also in the On change event on the Contact Field.  I think is something with the Code...

  • Community Member Profile Picture
    on at
    RE: Error in field's customization javascript

    Hi Waqar! Thank you for your answer. I taking the code from a Video to use Soap and Rest functions, there it works but here not... I didn't understand all the code either like in the line 14... I'm going to correct the name part and clear my browser cache as you are suggesting me :) keep you posted!

  • Community Member Profile Picture
    on at
    RE: Error in field's customization javascript

    Thank you Guido! will do and let you know if it works :)

  • Community Member Profile Picture
    on at
    RE: Error in field's customization javascript

    Thank you all! After fix the JavaScript in the lines 4 and 5 it is working!!! Have an incredible day :)

    This is the new JS:

    ContactoChange = function()

    {

    var new_name=Xrm.Page.getAttribute("new_name").getValue();

    if (new_name == "") return null;

    var contactid=Xrm.Page.getAttribute("new_contact").getValue();

    if (contactid == null) return;

    // Rest

    XrmServiceToolkit.Rest.Retrieve(

    contactid[0].id,

    "ContactSet",

    null, null,

    function (result) {

    var emailaddress1 = result.EMailAddress1 ;

    alert(emailaddress1);

    },

    function (error) {

    equal(true, false, error.message);

    },

    false

    );

    //soap

    var cols = ["emailaddress1"];

    var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactid[0].id,cols);

    Xrm.Page.getAttribute("new_name").setValue(new_name+ retrievedContact.attributes["emailaddress1"].value);

    }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans