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)

unable to get property 'set value' of undefined or null reference CRM

(0) ShareShare
ReportReport
Posted on by

Hi, I am writing a basic jscript for CRM 2013.

When I try to check if my js works, it gave me the next error:

unable to get property 'set value' of undefined or null reference CRM.

I was trying to figure out what is the mistake I made but I can´t realize.

This is my js code:

function mailOnchange()
{

var lookup = Xrm.Page.data.entity.attributes.get("tps_email").getValue();
if (lookup === null) {
return false;
}

if (lookup[0].id == null) {
return false;
}

var columns = ["subject", "description", "from"];

var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", lookup[0].id, columns);

//Seteo el valor del titulo de la busqueda
var name = Xrm.Page.data.entity.attributes.get("tps_titulo");
name.setValue(retrievedEmail.attributes.subject.value);


//Cargo el mensaje del mail
var descripcion = Xrm.Page.data.entity.attributes.get("tps_descripciondepuesto");
descripcion.setValue(retrievedEmail.attributes.description.value);

setIframe(retrievedEmail.attributes.description.value);


//Seteo al referente de la busqueda (el que me mando el mail)
var referente = Xrm.Page.data.entity.attributes.get("tps_referente");

var contact = retrievedEmail.attributes.from.value[0];

var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = contact.id;
lookupValue[0].name = contact.name;
lookupValue[0].entityType = "contact";

referente.setValue(lookupValue);

UpdateAccount(contact);

return true;
}

Thanks!

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    Thanks to everyone!

    All answers were useful to solve my problems.

    Regards.

  • Verified answer
    Royal King Profile Picture
    27,686 on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    try with below script , I just added checking to make sure field exists in the form before accessing it.

    function mailOnchange() {

       var lookup = Xrm.Page.data.entity.attributes.get("tps_email").getValue();

       if (lookup === null) {

           return false;

       }

       if (lookup[0].id == null) {

           return false;

       }

       var columns = ["subject", "description", "from"];

       var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", lookup[0].id, columns);

       //Seteo el valor del titulo de la busqueda

       if (Xrm.Page.getAttribute("tps_titulo"))

       {

           var name = Xrm.Page.getAttribute("tps_titulo")(retrievedEmail.attributes.subject.value);

           //name.setValue(retrievedEmail.attributes.subject.value);

       }

       //Cargo el mensaje del mail

       if (Xrm.Page.getAttribute("tps_descripciondepuesto")) {

           var name = Xrm.Page.getAttribute("tps_descripciondepuesto").setValue(retrievedEmail.attributes.description.value);        

       }

      // var descripcion = Xrm.Page.data.entity.attributes.get("tps_descripciondepuesto");

      // descripcion.setValue(retrievedEmail.attributes.description.value);

       setIframe(retrievedEmail.attributes.description.value);

       //Seteo al referente de la busqueda (el que me mando el mail)

       if (Xrm.Page.getAttribute("tps_referente")) {

           var referente = Xrm.Page.getAttribute("tps_referente");

           var contact = retrievedEmail.attributes.from.value[0];

           var lookupValue = new Array();

           lookupValue[0] = new Object();

           lookupValue[0].id = contact.id;

           lookupValue[0].name = contact.name;

           lookupValue[0].entityType = "contact";

           referente.setValue(lookupValue);

       }

       UpdateAccount(contact);

       return true;

    }

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    var name = Xrm.Page.data.entity.attributes.get("tps_titulo");

    Is your tps_titulo attribute on Form?

    if not you need to add that attribute on form..

  • Community Member Profile Picture
    on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    I have read everything you told me, thanks.

    And I remplaced with the rigth syntax.

    But now I debugged my js and the problem is in this line:

    name.setValue(retrievedEmail.attributes.subject.value);

    The error is Object doesn´t not support property or method setValue.

    Anyone can help me with this?

    Regards.

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    try changing this

    Xrm.Page.data.entity.attributes.get("tps_email").getValue();

    to

    Xrm.Page.getAttribute("tps_email").getValue();

    Also, you can add debug your code using any browser.

    Here are details on how to debug

    msdn.microsoft.com/.../gg699336(v=vs.85).aspx

    msdn.microsoft.com/.../dd565625(v=vs.85).aspx

  • Community Member Profile Picture
    on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    I have checked and tps_referente exists in the form.

    Besides I have changed the syntax as you suggested me, but now this error appears:

    campo: tps_email

    Evento onchange.

    Error: Unable to get property contentWindow of undefined or null reference.

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    Hi..

    It look like your "referente" is not found or "referente" variable is null.

    This generally happens that attribute is not on form, or any spelling mistake you did in attribute name.

    Common syntax is like

    Xrm.Page.getAttribute("name").setValue("new name");

    in your case you can try like

    Xrm.Page.getAttribute("tps_referente").setValue(lookupValue);

    Here are some more details on form scripting

    msdn.microsoft.com/.../jj602964.aspx

    msdn.microsoft.com/.../gg328261.aspx

    Hope this will help..

  • Suggested answer
    ScottDurow Profile Picture
    21 on at
    RE: unable to get property 'set value' of undefined or null reference CRM

    It looks like the line that gets the attribute is not finding it with that name:

    Xrm.Page.data.entity.attributes.get("tps_referente");

    Check that the name 'tps_referente' exists on the form.

    You might like to re-write:

    Xrm.Page.getAttribute("tps_referente");

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