Create ID based on two columns

rss

Posted by ACC - Jan 16 ’17 at 11:54

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.

 

 

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 23 days
    #1 by Dmitry Kozlov Jan 17 ’17 at 09:26

    Hi,

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

    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:

    fd.field('Job Number').change(setAutoID());

    Must be:

    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
    Member
    Member for: 2 years 8 months 28 days
    #2 by ACC Jan 17 ’17 at 06:58

    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);

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 23 days
    #3 by Dmitry Kozlov Jan 18 ’17 at 04:50

    [#2]: Please, fix your code:

    fd.field('FileLeafRef').value(fd.field('Job_x0020_Number').value());

    Read the following post describing how to get/set fields of various types:

    http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html

  • ACC
    Member
    Member for: 2 years 8 months 28 days
    #4 by ACC Jan 18 ’17 at 08:01

    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);

Displaying 1 to 4 of 4 messages