Not applicable

(javascript) How do I populate data into fields based on a selection picked in a look up column?

I am having trouble trying to figure this problem I have. In a list called “NewHireTermination” and I have a choice column called action that has choices of “New Hire” or “Termination”.

newhire.jpg

We have other columns called: employee name, title and start date. When a new person gets hired, you create a new line item choosing “New Hire” and fill out the employee name, title, and start date.

 

Now once an employee is about to be terminated, you select “Termination” in the action and you see the a drop down list of employees that have been added to the list via new hire. (TerminatedEmployee is a look up column for FullName.)

newhireterm.jpg

 

How do you update the fields of the new line item for “Termination” with the values from the “New Hire”. If I chose Jon Ngo in the Terminated Employee field, I want the other fields to update with Jon Ngo values from New Hire (FullName: Jon Ngo Title: Analyst, StartDate: 12/9/2015). It does not need to show up in the form, I just need it to update in the list.

newhirelist.png

0 Kudos
Reply
5 Replies
fhunth
Workflow Veteran

Re: (javascript) How do I populate data into fields based on a selection picked in a look up column?

I think you could create a workflow to start when Action = Termination

Then use the action named Query List filtering by Fullname and Action = 'New Hire', in the result you can get the ID of the item.

Then use the action Update item filtering by ID.

0 Kudos
Reply
Not applicable

Re: (javascript) How do I populate data into fields based on a selection picked in a look up column?

No I am looking for a javascript answer, but thank you. I have tried using lookup data and putting it into a calculated field, but on a form you cannot have 2 controls connect to the same column. Lookup data from another list inside a Nintex Form | Walking the stack

0 Kudos
Reply
Not applicable

Re: (javascript) How do I populate data into fields based on a selection picked in a look up column?

NWF$(document).ready(function(){ 

var obj = NWF$("#" + Name); 

obj.change(function(){ 

      var web = clientContext.get_web();   

      var List = clientContext.get_web().get_lists().getByTitle('NewHireTermination'); 

      var listItem = List.getItemById(this.value);  

      clientContext.load(listItem, 'FullName', 'Title');  

      clientContext.executeQueryAsync(function(){  

      var FullName = NWF$("#" + FullName);

      var Title = NWF$("#" + Title);

      FullName.val(listItem.get_item('FullName')); 

      Title.val(listItem.get_item('Title'));

}, 

function(){ alert("Error");}); 

}); 

}); 

Can someone let me know what I am doing wrong with this javascript? Name is the js client ID for Terminated Employee control.

0 Kudos
Reply
Not applicable

Re: (javascript) How do I populate data into fields based on a selection picked in a look up column?

I solved it.

 

NWF$(document).ready(function () {

    var obj = NWF$("#" + TerminationDropdown);

obj.change(function () {

  var clientContext = SP.ClientContext.get_current();

        var web = clientContext.get_web();

        var oList = clientContext.get_web().get_lists().getByTitle("NewHireTermination");

        var listItem = oList.getItemById(this.value);

        clientContext.load(listItem, "FullName", "Title", "Department", "StartDate");

        clientContext.executeQueryAsync(function () {

 

   document.getElementById(varFullName).value = listItem.get_item('FullName');

   document.getElementById(employeeTitle).value = listItem.get_item('Title');

   document.getElementById(DepartmentList).value=listItem.get_item('Department').get_lookupId();

   document.getElementById(varStartDate).value=listItem.get_item('StartDate').format('MM/dd/yyyy');

  

  

        }, function () {

 

 

        });

    });

});

0 Kudos
Reply
mwan001
Canvas Initiate

Re: (javascript) How do I populate data into fields based on a selection picked in a look up column?

clientContext.executeQueryAsync(function  code not working @

0 Kudos
Reply