How to copy lookup value to another lookup column?

Hi,

I have 2 forms. When user fill in Form A, it will automatically copied to Form B also with certain information needed from Form A copied to Form B; all fields are successful except sub-list library which cannot be display in Form B because of different lookup.

This is the sub-list library that user will fill in from Form A and can be view also from Form B when open separately. The sub-list library also available in Form B in case user fill up directly from Form B.

This sub-list has 2 lookup columns.
Lookup is set as 'GetSDCSR' from Form A while 'GetParent' from Form B.


I need value from 'GetSDCSR' to be copied to 'GetParent' column in order for this sub-list library able to display in Form B. How to make it possible? Tried using workflow designer 2013 but not able to copy it.

Dear @noorshahida88,
Unfortunately, I don't think I understand the case fully... You have 2 copies of the same List or Library on the form filtered by different fields? Do you want to have just one filtered by both? Do you want to populate some field in List or Library on change? And you're running it in Inline editing mode, right?

  1. You can populate fields from parent form in Inline editing with JavaScript. Please, check article for this - https://plumsail.com/docs/forms-sp/how-to/list-or-library-inline.html
  2. If you want to filter by two fields, that's also possible, but you'll need to create a custom CAML filter for List or Library - https://plumsail.com/docs/forms-sp/how-to/caml-filter.html

Hi @Nikita_Kurguzov, thanks for reply.

Let me be specific, I have 3 list libraries; named Form A, Form B, SubList C.

SubList C is only a lookup list in Form A and Form B.
In Form A, SubList C lookup field = GetSDCSR
In Form B, SubList C lookup field = GetParent

When user submit Form A, workflow will auto-generated new item in Form B with certain fields from Form A will be copied to new item in Form B.

When user click the auto-created new item in Form B, they should able to view the SubList C inside also. This is not happening because the lookup field only available to one list at a time. That is why I created another lookup field for SubList C for Form B.

How am I able to copy this lookup field value?
I need the lookup value GetSDCSR to be auto copy to GetParent.

I able to view SubList C in Form B if I change it manually but of course it shouldn't happen that way.

I've tried with SharePoint Designer before using set field and update list actions but the lookup value cannot be copy.

Please help me.

Dear @noorshahida88,
Why not create another Workflow which would auto-populate the GetParent field with a value from GetSCDSR field? You could also do it with pnpjs, just need to find the right moment - maybe when FormB opens, get some items from SubList C and copy GetSCDSR value to GetParent field, then refresh List or Library control.

Dear @Nikita_Kurguzov, I'm not familiar with pnpjs. Can you explain further? I've tried auto-populate by creating another workflow but doesn't works. Do you have an example for this?

Dear @noorshahida88,
You've got quite a complex case, so it's hard for me to replicate and test, but look at this. I've got a list with 2 Lookup fields (both to itself), but one is filled and one is empty. I'm filtering my List or Library by an empty field.

That's why when the Edit form opens, I'm finding all items where the GetParent column is empty, and copy the GetSCDSR value to it, check it out:

Here's the code:

var listOrLibraryName = 'SPDataTable1';
var list = pnp.sp.web.lists.getByTitle("CopyLookupList");
fd.spRendered(function(){
    list.getListItemEntityTypeFullName().then(function(entityTypeFullName){
        list.items.select("ID", "GetSCDSR/ID").expand("GetSCDSR").filter("GetParent eq null").get().then(function(items){
          var batch = pnp.sp.web.createBatch();
          items.forEach(function(item){
            var itemID = item.ID;
            var lookupID = item.GetSCDSR.ID;
            list.items.getById(itemID).inBatch(batch).update({
                GetParentId: lookupID
            }, "*", entityTypeFullName);
          });
          batch.execute().then(function(){
            fd.control(listOrLibraryName).refresh();
          });
        });
    });
});