Cannot get lookup value in Child form on load

Hello
I have a parent form and a sub child list.
when i click for a new record in child list the dialogue form is open normally and related lookup in relation with parent get value automatically (Foreign Key related lookup field)

My problem is on loading of the dialogue if i try to get the lookupvalue and ID of the Lookup field (the foreign key lookup) in order to use it to fill the Title and other fields by code i am getting “Object object” as value or error or blank…

script i tried to use to test and figure out the problem:
Fields:_

  • Lookupfield Foreign Key: fd.field(‘PersonIDfk’)
  • Another required lookup: fd.field(‘PersonNationalityID’) that i fill it with a default value on load.
    I use these two fields values to fill the Title and i can’t get the values on load.

First Attempt:
//Set Title Value
function FncSetTitle() {
// Set Title Value
var str1 = fd.field(‘PersonIDfk’).widget.datasource.data();
var str2 = fd.field(‘PersonNationalityID’).widget.datasource.data();
fd.field(‘Title’).value = str1 + " " + str2;
}

Second Attempt:
//Set Title Value
function FncSetTitle() {
// Set Title Value
var str1 = fd.field(‘PersonIDfk’).value.LookupValue;
var str2 = fd.field(‘PersonNationalityID’).value.LookupValue;
fd.field(‘Title’).value = str1 + " " + str2;
}

Third Attempt:
//Set Title Value
function FncSetTitle() {
// Set Title Value
var str1 = fd.field(‘PersonIDfk’).value;
var str2 = fd.field(‘PersonNationalityID’).value;
fd.field(‘Title’).value = str1 + " " + str2;
}

Then i call the scripts on load
//On load set nationality default value to 114 (the ID of Lebanon)
fd.field(‘PersonNationalityID’).value = 114;

//On load fill the Title
FncSetTitle();

can i get a clear solution for this please.

Dear Georges,

The second attempt is a right one. Have you placed it in the “ready” event handler for lookup field? https://plumsail.com/docs/forms-sp/javascript/fields.html#events

If this doesn’t help, could you please provide the screenshot of the browser console?

Dear @AlexZver,
first thank you for your help.

for the .value.LookupId (Second attempt) is not working getting Undefined value even with .ready function.

Really it is a hard work and wasting of time.
It should be easier and with less coding.
I think it is a problem when we try to get a lookup value in dialogue form status of new record of a child list.

i am using this function now to get values but still have problems:

//Create Fnc Set Title Value
function FncSetTitle(str1, str2) {
    fd.field(str1).ready().then(function () {
        //fd.field(str1).widget.dataSource.data();
        return fd.field(str2).ready();
    }).then(function () {
        var str1Array = fd.field(str1).widget.dataSource.data();
        var str2Array = fd.field(str2).widget.dataSource.data();
		
		var strPart1 = "";
		var strPart2 = "";

        if (fd.field(str1).value && fd.field(str2).value) {
            for (i = 0; i < str1Array.length; i++) {
                if (str1Array[i].ID === fd.field(str1).value.LookupId) {
                    console.log(str1Array[i].LookupValue);
                    strPart1 = str1Array[i].LookupValue;
                    break;
                }
            }
            for (i = 0; i < str2Array.length; i++) {
                if (str2Array[i].ID === fd.field(str2).value.LookupId) {
                    console.log(str2Array[i].LookupValue);
                    strPart2 = str2Array[i].LookupValue;
                    break;
                }
            }
		
             //Set Title Value
            fd.field('Title').value = strPart1 + " - " + strPart2;
			//Duplication field
			fd.field('CheckForDuplication').value = fd.field(str1).value.LookupId + " - " + fd.field(str2).value.LookupId;
         }
    });
}

the function works if i select the lookup value by hand.
wherever if i pass the lookup a value by script and set the lookup control disabled= true and tried to get lookup id i am getting "undefined " and null as value.

check plz 2 screenshots:

Dear @AlexZver, seems there is problem with plumsail on dialogue form
the solution is not working even with .ready function still i can’t get the lookup value on load especially the (foreign key) lookup control.

However i tried to finalize this problem on my own using the below script after i surrendered:

function FncSetTitle() {
        var str1 = "PersonConfessionPersonIdFk";
        var str2 = "PersonConfessionIdFk";

        var strPart1 = "";
        var strPart2 = "";

        fd.field(str1).ready().then(function () {
            return fd.field(str2).ready();
        }).then(function () {
            var fdValue = fd.field(str1).value.LookupId ? fd.field(str1).value.LookupId : fd.field(str1).value;

            if (fdValue) {
                pnp.sp.web.lists.getByTitle("PersonList").items.getById(fdValue).get().then(function (item) {
                    console.log(item);

                    strPart1 = item.PersonfullName;

                    //Set Title Value
                    fd.field('Title').value = strPart1;

                    var fdValue = fd.field(str2).value.LookupId ? fd.field(str2).value.LookupId : fd.field(str2).value;

                    if (fdValue) {
                        pnp.sp.web.lists.getByTitle("ConfessionList").items.getById(fdValue).get().then(function (item) {
                            console.log(item);

                            strPart2 = item.ConfessionName;

                            //Set Title Value
                            fd.field('Title').value += " Confession: " + strPart2;

                        });
                    }
                });
            }
        });
}

i suggest you that you try to get a lookup value and lookup id using your method from a child list in dialogue form and check if it is working with .ready i will be happy to use less codes.

I agree. I still cannot get Lookup Values via the Dialog.Open() function, only text and Choice fields. My list has many lookup lists and it would be nice if we can have this functionality.

Hello @CWF,

Do you want to pass the value from the parent form to the child opened in a dialog?

If so you can find instructions in this article:

And if you need to get extra values from the lookup field that was set programmatically, please see this post: