Assigning associated lookup columns to related items

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Karlostavitch
Posts: 20
Joined: Wed Aug 24, 2016

19 Dec 2016

In relation to prefilling fields via jquery for related items.

So I assume you have to assign lookup fields by the ID.

In the case of a person, this is also a kind of lookup field. Is it possible to get the ID of a person nominated in the parent form and assigning that value to the child related items? In the same context, is is possible to get the ID from a lookup field in the parent item and assigning it to the child related item?


Many thanks,

Karlostavitch
Posts: 20
Joined: Wed Aug 24, 2016

21 Dec 2016

I can just assign it by creation workflow if it can't be done in the form.

YuriyMedvedev
Moderator
Posts: 33
Joined: Wed Sep 21, 2016

22 Dec 2016

Hi, just add to related-items-block class "related-items", set "Client" rendering and "Quick-edit" mode to "Only" and use this code:

Code: Select all

fd.field('User').control('ready', function() {

    if(fd.field('User').value().length == 0)

        return false;

    var clientContext = SP.ClientContext.get_current();

    var website = clientContext.get_web();

    currentUser = website.ensureUser(fd.field('User').value()[0].Key.split('|')[2]);

    clientContext.load(website);

    clientContext.load(currentUser);

    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);



    function onRequestSucceeded() {

     var userid =  currentUser.get_id();

     fd.populateFieldsInGrid($('.related-items'), {

            Title: 'CurrentItem',

            Link: "https://google.com",

            Lookup: fd.field('Lookup').value() || '',

            User: userid,

        });

    

    }



    function onRequestFailed(sender, args) {

      alert('Error: ' + args.get_message());

    }

})
Where "Lookup", "User" are names of your fields.

So, now you can create new items in "related items" and they will have in fields "Lookup" and "User" values of parent

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests