Put two values in a field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Eax
Posts: 32
Joined: Wed Oct 28, 2015

28 Oct 2015

Hello,

I want to made a form with a choice menu and two simple line text. My question is if it's possible to set two values on a field.

Second : in the other field, i need to put a number automatically when a new form is created.

Exemple :

I made a new form :

Image

And when in "Type_Montant" I select "Avenant" for exemple, i want to put it automatically in my field "Libelle" : "Avenant 1"

The "1" is because i want to generate my field "Numero" a number 1 to 99 :

Image

Best regards,

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

29 Oct 2015

Hello!

1. Yes, it is possible. For example, like this:

Code: Select all

fd.field('Libelle').value(fd.field('Type_Monant').value() +' ' + fd.field('Numero').value());
2. I'm not clear as to how you want to generate that number. If you simply want a random number from 1 to 99, here's a snippet for you(add it to the JS editor for the form in Forms Designer):

Code: Select all

function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
}
var rnd = getRandomArbitrary(1,100).toString();
fd.field('Numero').value(rnd.substring(0, rnd.indexOf('.')));
Note, that if you want an ID field, there is already one built in in every SharePoint list. But it is available only after the creation of a record, since that's when the ID is assigned.

3. Use the following code:

Code: Select all

//in the case if Type_Monant is a choice field
function assign () {
	fd.field('Libelle').value(fd.field('Type_Monant').value() +' ' + fd.field('Numero').value());
}
//in the case that Type_Monant is a lookup field
function assign () {
	fd.field('Libelle').value(fd.field('Type_Monant').control('getSelectedText') +' ' + fd.field('Numero').value());
}

fd.field('Type_Monant').change(assign);
Note, that of course, you'll have to replace Internal Names as and if appropriate. An Internal Name of a field can be checked by clicking the field in Forms Designer and checking the grid on the right hand side.

Eax
Posts: 32
Joined: Wed Oct 28, 2015

09 Nov 2015

Work great, thanks

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests