Page 1 of 1

Assigning associated lookup columns to related items

Posted: 19 Dec 2016
by Karlostavitch
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,

Re: Assigning associated lookup columns to related items

Posted: 21 Dec 2016
by Karlostavitch
I can just assign it by creation workflow if it can't be done in the form.

Re: Assigning associated lookup columns to related items

Posted: 22 Dec 2016
by YuriyMedvedev
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