The Pesky Name Field on Custom Entities

When you create a new custom entity by default, it creates a field called Name that is used on lookups, etc. If you don't use the field, it can cause some headaches.  I have been using this as an area to store some information that would make searching on it much easier and automatically fill in the field. (So I don't have to type any more than necessary.)

Shad from Illinois who is a customer who contacted my about some other issues and after pointing him in the right direction for this, he shared back his code for us. 🙂 Thanks Shad! So in his case he has both the contact and the account linked to the custom entity.  In the OnSave area he put this code. You could put it in On Save or OnLoad or an OnChange.

var lookupItem = new Array;

var contactName = new Array;

// This will get the lookup for the attribute primarycontactid on the Account form.

lookupItem = crmForm.all.new_companynameid.DataValue;

contactName = crmForm.all.new_contactnameid.DataValue;

// If there is data in the field, show it in a series of alerts.

if (lookupItem != null)


   // The text value of the lookup.

   crmForm.all.new_name.DataValue = lookupItem[0].name + " - " + contactName[0].name;

crmForm.all.new_name.ForceSubmit = true;




crmForm.all.new_name.DataValue = contactName[0].name;

crmForm.all.new_name.ForceSubmit = true;


Comments (6)

  1. Jon G says:

    Just an FYI.  Because it’s client side scripting, you can’t be assured that the name field will be updated by bulk edits, workflow updates, plugin updates, etc…  It will only take place when a manual entry is made on the form.

  2. Chris says:

    We do this in precreate and preupdate callouts (3.0) and plugins (4.0) to account for the scenario Jon G points out above. We’ve toyed with the idea of doing as workflows in 4.0 to make it more transparent to the client, but we’re afraid of the overhead.

  3. This is an alternative method of doing the same thing we talked about with this post.   John G from

  4. Bill Smith says:

    do you know how to "inherit" the attributes of an "out of box" entity.

    I need to have a "classroom" entity identical to a "facility" entity.

  5. Bertil says:


    I found this type of scripting to be very usefull, but tricky. Because as in the example the total length of what you’re trying to put in the field may be longer than the field you’re trying to put it into. So to avoid errors, I’ve changed the script to trim the value:

    //Generate the value for the name field

    var Eventname = ”;

    var Employeename = ”;

    var EnrolmentnameConcat = ”;

    //Set Eventname

    if (crmForm.all.wfv_educationassessmentid.DataValue != null)


    Eventname = crmForm.all.wfv_educationassessmentid.DataValue[0].name;


    //Set Employeename

    if(crmForm.all.wfv_employeeid.DataValue != null)


    Employeename = crmForm.all.wfv_employeeid.DataValue[0].name;


    //Create value before lenght check

    EnrolmentnameConcat = "of " + Employeename + " for " + Eventname;

    //Set name value with max field length

    crmForm.all.wfv_name.DataValue = EnrolmentnameConcat.substring(0,99);

  6. This is an alternative method of doing the same thing we talked about with this post.   Jon G from

Skip to main content