Discussion:
Get Schema and/or Display name of fields in JavaScript
(too old to reply)
msandid
2010-03-29 23:18:29 UTC
Permalink
Hi all,

Is there a property of fields in CRM that returns their schema and/or
display name?

I am looping through all the fields of a form and would like to return
a list of the names of the fields that changed value. I am doing this
in the OnSave event and I kept playing with "name" and "ID" but it
usually returns "unidentified."

On a separate note, do I have to add a new attribute to the form so
that I can refer to it in JavaScript? If I don't do that, I get a JS
error! Probably because I am referring to this new field using the
form name: form.new_fieldname. Is there another way to refer to it and
populate it, maybe using document or entity name as a handle?

I'm a JS beginner and code samples would help. Thank you,
Mohamed
msandid
2010-03-29 23:27:24 UTC
Permalink
Post by msandid
Hi all,
Is there a property of fields in CRM that returns their schema and/or
display name?
I am looping through all the fields of a form and would like to return
a list of the names of the fields that changed value. I am doing this
in the OnSave event and I kept playing with "name" and "ID" but it
usually returns "unidentified."
On a separate note, do I have to add a new attribute to the form so
that I can refer to it in JavaScript? If I don't do that, I get a JS
error! Probably because I am referring to this new field using the
form name: form.new_fieldname. Is there another way to refer to it and
populate it, maybe using document or entity name as a handle?
I'm a JS beginner and code samples would help. Thank you,
Mohamed
I have figured out that the property "id" (all small letters) returns
the schema name of a field. Now if I could only get the display name
as well!

Also, how do I refer to a new field using JavaScript without having to
add it to the form?

Thanks again.
RhettClinton
2010-04-04 22:36:01 UTC
Permalink
To get the label of a field use crmForm.all.new_yourfieldname_c.innerText

Also you cannot reference a field if it is not on the form. Use javascript
and call the crm webservice.
Post by msandid
Post by msandid
Hi all,
Is there a property of fields in CRM that returns their schema and/or
display name?
I am looping through all the fields of a form and would like to return
a list of the names of the fields that changed value. I am doing this
in the OnSave event and I kept playing with "name" and "ID" but it
usually returns "unidentified."
On a separate note, do I have to add a new attribute to the form so
that I can refer to it in JavaScript? If I don't do that, I get a JS
error! Probably because I am referring to this new field using the
form name: form.new_fieldname. Is there another way to refer to it and
populate it, maybe using document or entity name as a handle?
I'm a JS beginner and code samples would help. Thank you,
Mohamed
I have figured out that the property "id" (all small letters) returns
the schema name of a field. Now if I could only get the display name
as well!
Also, how do I refer to a new field using JavaScript without having to
add it to the form?
Thanks again.
.
msandid
2010-04-06 21:08:02 UTC
Permalink
On Apr 4, 5:36 pm, RhettClinton
Post by RhettClinton
To get the label of a field use crmForm.all.new_yourfieldname_c.innerText
Also you cannot reference a field if it is not on the form. Use javascript
and call the crm webservice.
Post by msandid
Post by msandid
Hi all,
Is there a property of fields in CRM that returns their schema and/or
display name?
I am looping through all the fields of a form and would like to return
a list of the names of the fields that changed value. I am doing this
in the OnSave event and I kept playing with "name" and "ID" but it
usually returns "unidentified."
On a separate note, do I have to add a new attribute to the form so
that I can refer to it in JavaScript? If I don't do that, I get a JS
error! Probably because I am referring to this new field using the
form name: form.new_fieldname. Is there another way to refer to it and
populate it, maybe using document or entity name as a handle?
I'm a JS beginner and code samples would help. Thank you,
Mohamed
I have figured out that the property "id" (all small letters) returns
the schema name of a field. Now if I could only get the display name
as well!
Also, how do I refer to a new field using JavaScript without having to
add it to the form?
Thanks again.
.
Thanks Rhett. Your code works great when working with a pre-determined
list of fields. However, I am actually looping through all the fields
on the form to see which was changed using this code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var modifiedField = crmForm.all.new_modifiedfields; //Field to hold
list of name/value of modified fields
modifiedField.DataValue = "";
for (i=0; i<crmForm.all.length; i++)
{
var ChangedField = crmForm.all[i]; //variable field to look thru all
fields
if (ChangedField.IsDirty == true)
modifiedField.DataValue = modifiedField.DataValue +
ChangedField.innerText + "|" + ChangedField.DataValue + "; " ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Can you suggest a way to change the code above to use your code
new_yourfieldname_c.innerText?
The problem is that, as I am looping thru the fields using an array, I
am not referring to each field individually so I cannot suffix its
name with "_c".

Continue reading on narkive:
Loading...