2

I am designing an infopath (Change Request) form:

1)How can i add a text box that automaticaly increments to the next number when a new form is created (adding a new Change Request form to the form library).

2)How do i retrieve information from an existing form to the new form.

NOTE: The field is not inside a repeating table. I need to generate the next Change Request number on each new Change Request form.

TIA!

Leon Tayson
  • 4,741
  • 7
  • 37
  • 36

2 Answers2

2

There is no build-in way to do this, but there are several ways to achieve what you want (Database query or SPList query). But this kind of request somehow smells like a workaround for an other problem. Common cases for increasing numbers are:

  • unique IDs
  • count the Requests
  • make referable by external list (same as ID)
  • make IDs guessable (time stamps are not)

If you need an ID: In most cases you are not forced to use integer IDs. Simply use the form title as a natural ID. (e.g. customer + timestamp)

If you need guessable IDs, you need them because an external system wants to access or refer to the request. In that case try to change the pull-direction into a push-direction (e.g. by using workflows) or let your other system provide a "getID" function that can be called by your form to obtain a known ID (no guessing needed).

Anyway - for me, it looks like you want to achieve this to solve some other problem. Maybe there are different solutions for that problem too?

MrFox
  • 3,233
  • 6
  • 25
  • 27
0

You could enter a token in your text-titles on the form where you want autonumbering, such as #num#, and then use javascript or jquery to find those tokens and replace them with incremented numbers.

The drawback to this is that if you exported the list to excel, the tokens would not get translated to numbers. But it is a good solution for on-screen rendering.

Use Firebug to figure out the class of the container housing your autonumber tags. Maybe you could do something like this:

function TokenReplacement(){
    var ClassName = 'ms-formlabel';
    var elements = new Array();
    var elements = document.getElementsByTagName('td'); 
    var numerator=0;
    //Now do find and replace on everything else
    for(var e=0;e<elements.length;e++){
        thiselement = elements[e];
        if(thiselement.className == ClassName){
            //autonumber the questions by replacing the #num# token
            if(thiselement.innerHTML.search('#num#') > -1){
                numerator++
                var replacenum = "<b>" + numerator + ".&nbsp;&nbsp;</b>";
                thiselement.innerHTML = elements[e].innerHTML.replace('#num#',replacenum);  
            }
        }
    }
}
bgmCoder
  • 6,205
  • 8
  • 58
  • 105