1 2 Previous Next 15 Replies Latest reply: Jul 13, 2012 1:23 PM by Link RSS

Initializing a field with value.

William NameToUpdate

Hello all,

 

I have a question that is probably something simple that I am overlooking. I am trying to initialize a field on a dependent form with a value from the landing page. After I could not get this to work, I simply tried:

 

document.dependeefields.Report__bType__c.value = "Hello World!";

 

This still did not show up in the field. I copied the field name from source and this actually works:

 

document.dependeefields.Report__bType__c.title = "TESTING 1-2-3";

 

Is there any field setting that would not allow this functionality or am I just using the wrong tool for the job?

 

Thanks in advance!

 

[FootPrints v10.0.2]

  • 1. Initializing a field with value.
    Johan Gouverneur

    Could you clarify what you want to accomplish? I'm getting the feeling that you are using javascript to populate a field with a value, however since you did not include it I can only guess to what are attempting.

     

    What is your field called?

     

    The "__c" translates to ":" which would be ok for the HTML itself, but I don't think that it will be necessary for your population as I don't think that's actually in the field name.

     

    Maybe you can post the script that you have so far, so we could take a look at it.

  • 2. Initializing a field with value.
    William NameToUpdate

    I'm sorry. Yes I am using Javascript in the field header section of a form. The field name is Report Type: which is a mandatory single line char field. How do I place a value in this field via script? The code that I am using is:

     

    <script language=javascript>

    document.dependeefields.Report__bType__c.value = "Hello World!";

    </script>

     

    Is this correct or am I supposed to be using another way?

     

    Let me know if this is not clear or if you need more information.

     

    Thanks!

  • 3. Initializing a field with value.
    Jean Abou-Diwan

    Hi William,

     

    Try this... it works for me.

     

    Cheers,

    Jean

                                                                                                        

    <script type="text/javascript">

    //This function will get triggered after 5 seconds

    setTimeout("apres_chargement()",5000);

    function apres_chargement() {

                    getinforeport();

    }

    //set report type to HELLO WORLD

    function getinforeport()

    {

    var inforeport = “Hello World”;

    document.getElementsByName("Report__bType__c").item(0).value = inforeport;

    }

    </script>

  • 4. Initializing a field with value.
    Jean Abou-Diwan

    And don't forget to put this code at the end of your Form Designer.

  • 5. Initializing a field with value.
    William NameToUpdate

    Thank you but unfortunately, this did not work. I also tried just:

     

    <script type="text/javascript">

    document.getElementsByName("Report__bType__c").item(0).value = "Hello World";

    </script>

     

    Which I also thought should work but it did not. There has to be something that I am missing because this seems like a simple task.

  • 6. Initializing a field with value.
    Michael Santos

    William,

     

    When you say it doesn't work, are you getting a JavaScript error?  When I work with Field Headers, I like to use Firefox with Firebug enabled so I can easily see what the error is.

     

    Can you share a screenshot of how your form looks, where the fields are and what your field headers screen looks like?  For the Report Type: field, is this in a pop-up dependency?

     

    Michael

     

    Michael Santos

    Software Consultant
    BMC Software

  • 7. Initializing a field with value.
    Jean Abou-Diwan

    FYI, It's case sensitive! ( Report__bType__c)

  • 8. Initializing a field with value.
    Link

    I'm guessing you are on v9 or v10 since you are using the document.dependeefileds. One way to set a dependent field value will be to put the code in the pop up somewhere, this is simplified in v11 since pop ups are removed, you will need to have a field below the "Report Type" field in the pop up that can hold the code in the Field Header.

     

    The other thing you can try is to have the dependency retain the previous values entered, which is set when you create the dependency, so it will hold any value you enter instead of discarding it when edited.

     

    And yes if you have any type of special character in your field name like ":" it is stored in the column name so it is required in the code as well.

  • 9. Initializing a field with value.
    William NameToUpdate

    Thanks Aaron,

     

    I am using [FootPrints v10.0.2].

     

    The field is named Report Type: so I tried the following methods in the Field Header section to initialize it:

     

    <script language=javascript>

    document.dependeefields.Report__bType__c.value = "Hello World!";

    </script>

     

    <script type="text/javascript">

    document.getElementsByName("Report__bType__c").item(0).value = "Hello World";

    </script>

     

     

    I changed .value to .title to make sure that the field name (copied from page source) was correct and it displayed the Tooltips as expected.

     

    The field is not a pop-up and the field definition is:

    Character(Single line)

    Public Read-Write-Edit Mandatory

    Length Restriction - None

     

    Neither options described above work(meaning nothing shows up in the field) and I am trying to find out why and what function do I need to use to accomplish this task.

     

    Any suggestions or explanantions?

     

    Thanks again!

  • 10. Initializing a field with value.
    Link

    Because of the way the form is built you have to put the JS code in a field header below the field you are wanting to manipulate.  So if you are putting this code in the "Report Type:" header field then it will error out because the header field is created before the actual input field.

     

    Is the "Request Type:" field part of a depenecy pop up?  if not then the code will be document.regform not document.dependeefields.

  • 11. Initializing a field with value.
    William NameToUpdate

    Thanks Aaron,

     

    Yes I place the JS code in a field below the field in question. Yes this field is on a dependent form pop-up. As I metioned the following code works to show tooltips so that verifies the field name as well as code placement. :

     

    <script language=javascript>

    document.dependeefields.Report__bType__c.title = "Hello World!";

    </script>

     

    But for some reason, I just cannot modify the value of this field using .value.

     

    Thanks again.

  • 12. Initializing a field with value.
    Michael Santos

    William,

     

    With your JavaScript in place, can you send me a zipped copy of your workspace directory?  The workspace directory is in the FootPrints\db\MASTERx location.  You can find out what MASTER your workspace is by going to Administration|System|Workspaces in the web interface and clicking the "Click here" link at the top of the page.

     

    I'd like to try your workspace setup in a 10.0.2 I have here.  Note, there will no data sent over.  It is simply the configuration of the workspace.

     

    You can either attach it to this thread or private message me.

     

    Thanks!

     

    Michael

     

    Michael Santos

    Software Consultant
    BMC Software

  • 13. Initializing a field with value.
    Link

    I tested with the same results so I added a setTimeout() statement to delay setting the value and it works.  Here is the timeout statement for 3 seconds:

     

    setTimeout("document.dependeefields.Report__bType__c .value = \"Hello World!\"", 3000);

  • 14. Initializing a field with value.
    William NameToUpdate

    Thanks Aaron! That does indeed work!

     

    So now...why deos that work? I thought that the reason we place code below the field we want affected is to allow for the top down loading of the page. Does this code suggest that there is a greater lag?

1 2 Previous Next