cancel
Showing results for 
Search instead for 
Did you mean: 

Element Ids in Custom Object javascript

JeffLamb
Contributor II


I have a very fundamental question regarding javascript in custom objects. How do I determine the element id of a field I want to reference in the javascript?

 

I have a simple requirement where we need to clear the contents of a text field when the record is opened for editing. Seems like it should be easy to implement this with a custom object, but I don't know how to get the element id of the field so I can reference it within the custom object.

 

If it matters, I'm using Archer 5.2 but we will be moving to 5.3 SP1 soon.

1 ACCEPTED SOLUTION

Accepted Solutions

DavidPetty
Archer Employee
Archer Employee

Its probably easier to use some short hand to get the element id's.

 

Just replace the value for the fldId with the field id.  You can get the file id by going to the Manage Application, select you application.  Go to the Fields tab.  Hover you mouse over the field and at the bottom right you see ID: 0000.

 

<script type="text/javascript">
var fldId = 13314;

Sys.Application.add_load(function() {
  $('input[id*="f' + fldId + 'c"]').val('');
  $('div[id*="f' + fldId + 'c"]').text('');
});
</script>

 Advisory Consultant - Archer, an RSA Business

View solution in original post

31 REPLIES 31

DavidPetty
Archer Employee
Archer Employee

Its probably easier to use some short hand to get the element id's.

 

Just replace the value for the fldId with the field id.  You can get the file id by going to the Manage Application, select you application.  Go to the Fields tab.  Hover you mouse over the field and at the bottom right you see ID: 0000.

 

<script type="text/javascript">
var fldId = 13314;

Sys.Application.add_load(function() {
  $('input[id*="f' + fldId + 'c"]').val('');
  $('div[id*="f' + fldId + 'c"]').text('');
});
</script>

 Advisory Consultant - Archer, an RSA Business

Thank you for posting that. It took care of my root question of identifying the field id.

 

Now what if I wanted the contents of that text field to be cleared only when there is a change to another (date) field? I tried using  syntax like this:

 

var DueDate = document.getElementById("fld14803"); //14803 is the field id of the date field

DueDate.attachEvent("onchange",clearReasonText); //clearReasonText is a function that clears the contents of the text field

 

But the clearReasonText function does not trigger.

Element references are no longer called that way in 5.x

 

See if this works for you

<script type="text/javascript">

var dateFldId = 14803;

var textFldId = 2222;

 

Sys.Application.add_load(function() {

  $('input[name*="f' + dateFldId + 'cdp"]').change(function() {

   $('input[id*="f' + textFldId + 'c"]').val('');

   $('div[id*="f' + textFldId + 'c"]').text('');

  });

});

</script>

 Advisory Consultant - Archer, an RSA Business

It does not. I put in a few lert statements to see if anything is executing. The alert statement between your lines 05 and 06 runs, but the one I put between your lines 06 and 07 does not when I make a change in the date field. Any ideas on debugging?

Sorry for the delay, give this a shot.

<script type="text/javascript"> 

var dateFldId = 14803

var textFldId = 2222

 

Sys.Application.add_load(function() { 

  $('div[id*="f' + dateFldId + 'cdp"]').change(function() { 

   $('input[id*="f' + textFldId + 'c"]').val(''); 

   $('div[id*="f' + textFldId + 'c"]').text(''); 

  }); 

}); 

</script> 

 Advisory Consultant - Archer, an RSA Business

Yes, that did it. Thank you very much.

Another thing I would like to be able to do is this: upon Archer record creation, default the selected value of a user/group list field to the selected value of another user/group list field contained in a cross reference. Is that possible?

 

In general, do you have a recommended resource that documents these types of javascript usage in Archer custom objects? The community is great, but you've already shown me that the syntax in some of the older postings is no longer valid. Is that due to a change in javascript, Archer, or both?

 

If I had something that I could refer to that would explain things like: why cdp vs. c or why div vs. input, then it would keep me from posting here unnecessarily. It may be that those questions are just basic javascript (I'm no javascript expert). If so, then knowing that will help me to better direct my efforts.

Nice....

 

Pulling users from a cross-reference field into the parent record is a little complex.  If you have record permisisons fields setup in both applicationa you can add an additional one configured for inheritance and then you can point to the inherited record permission field found in the cross-reference.

 

There isn't any available resource for using JavaScript in the framework.  The only breakage right now is when using custom objects designed for 4.x; they will not work in 5.x.  There was also some internal function changes that were introduced in 5.3.

 

A lot of the in elements found in the framework can be found using IE's Developer Tools (IE 8 or greater), F12 to invoke or Firefox's Firebug plugin.

 Advisory Consultant - Archer, an RSA Business

Hi David,

 

May I wonder after run this script, where is the element id being stored? So I can use it in the parameters of javascript functions such as getElementById(' ') ?

 

Thanks,

Not sure what you mean where the element id are be stored.

 

All fields have a field id that you can obtain by going to Manage Applications, select the application.  Go the Fields tab an hover your mouse over the field you want the id for.  The id will appear at the bottom right of the screen.

 

Then depending on how you are retrieving or setting a field value will determine how to get the element corresponding to the value you want.

 Advisory Consultant - Archer, an RSA Business