Create ID based on two columns

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ACC
Posts: 3
Joined: Mon Jan 16, 2017

16 Jan 2017

Hi, I am completely new to this. I am currently working on a small demo and it seems as if your solution maybe a good fit. I have downloaded and installed the demo version, which was simple. I am designing my first form. I would like to create an auto ID for the "Name" field on a Document Set. I have created a form for the New Form of the Document Set. I have two fields one is a single line of text, "Job Number: the other is an External data field, "Client". In my example I am just updating Name when either Job Number or Client changes. I would be open to a better solution as to when to update the Name field, not suse if you have some sort of "on close" event that I should update Name on. I would think the event has to occur before save occurs as Name is a required field. Well this is what I came up with and it doesn't work.

//Function to create the id and set it to the Name field

function setAutoID() {
//Get Job Number field single text field
var job = fd.field('Job Number').value();
//Get client name from external data field
var cust = fd.field('Client').value().dictionaryEntries[0]['Client'];
//create value for id = job + cust
var id = job +' '+ cust;
//set Name field to the id value
fd.field('Name').value(id);
}


// When the job number field changes update the id
fd.field('Job Number').change(setAutoID());

// When the client name changes update the id
fd.field('Client').change(setAutoID());

Thanks for any help.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

17 Jan 2017

Hi,

First, you have to use internal names of fields in your code. An internal name cannot contain spaces like here:

Code: Select all

fd.field('Job Number').value();
You can find the internal name of a field in its properties in Forms Designer.

Also, you have a syntax error here:

Code: Select all

fd.field('Job Number').change(setAutoID());
Must be:

Code: Select all

fd.field('Job Number').change(setAutoID);
The same with the next line. Our support team can assist you with the task, it will take 100 support minutes. If it's OK, purchase the support minutes in our store and provide temporary access to your site:

http://spform.com/buy

ACC
Posts: 3
Joined: Mon Jan 16, 2017

17 Jan 2017

Thanks for the reply. I am still running into a problem. I thinking that maybe i cannot set the value of the system field. I am attempting to set the Name field, InternalName "FileLeafRef". I have verified all the Internal Names and simplified my code but still nothing. I also tried to assign the value of "Job_x0020_Number" to a variable then use the variable to set "FileLeafRef". That didn't work.

// Funtion to set value

function setAutoID() {
fd.field('FileLeafRef').value() = fd.field('Job_x0020_Number').value();
}

//When value changes set other value via funtion

fd.field('Job_x0020_Number').change(setAutoID);

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

18 Jan 2017

Please, fix your code:

Code: Select all

fd.field('FileLeafRef').value(fd.field('Job_x0020_Number').value());
Read the following post describing how to get/set fields of various types:
http://spform.com/forms-designer- ... eld-values

ACC
Posts: 3
Joined: Mon Jan 16, 2017

18 Jan 2017

Thanks for the reply it is working. Here is the basic code if anyone in intrested.

function setAutoID() {
fd.field('FileLeafRef').value(fd.field('Job_x0020_Number').value() + "-" + fd.field('Client').value().dictionaryEntries[0]['cm_contact_no']) ;
}


// When the job number field changes update the id
fd.field('Job_x0020_Number').change(setAutoID);

// When the client name changes update the id
fd.field('Client').change(setAutoID);

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests