Lookup field is not being saved

Hi,

I'm opening a new list item form from another one (in dialog). To set the value of related lookup field I used this code.
fd.spRendered(function(){
fd.field("AssignedTicket").value = Dialog.getArgs().parentID;
});
I can see, the field is being set with its parent ID. After saving the form the lookup value get lost.
Any ideas what is going wrong here?
I also found a code example from @Nikita_Kurguzov , he mentioned to use fd.field('AssignedTicket').widget.dataSource.data() to set the lookup. Is that necessary?

thx
Alex

Hello @Alex,

How do you open the dialog? Are you using the List or Library control?

Hi mnikitina

I'm using this code from another form (the parent list)

dialogUrl = _spPageContextInfo.webAbsoluteUrl + "/SitePages/PlumsailForms/"+listName+"/CSM%20Comment/NewForm.aspx";

Dialog.open(dialogUrl,

    { parentID: parseInt(parentID), partnerID: parseInt(window.TicketPartnerID) },

    function (hasSaved) {

        if(hasSaved){

            //alert('Form in dialog has saved and closed.');

            //refresh related items after creation.

            window.getGroups();

            getComments(listTitle, window.itemId, "#ticketComments");

        }

        else{

            //alert('Dialog form was closed without saving!');

        }

     }//, 

    //{ width: 800, height: 600 }

);

@Alex,

You can pass parent item id to the form opened in dialog using the approach from this article:
https://plumsail.com/docs/forms-sp/how-to/pass-values.html

@mnikitina
the issue is not getting parent ID. I have the parent ID in the child form, I also set the value to the parent value.

fd.spRendered(function(){
fd.field("AssignedTicket").value = Dialog.getArgs().parentID;
});

After saving that, AssignedTicket lookup is empty. It is not empty after saving, if I pick the value manually from its dropdown. But it is empty if its being set by e.g.

fd.field("AssignedTicket").value = 105;

is it possible, that fields are not being saved if they are disabled by fd.field().disabled = true; ?

--> if I open the form directly (not in dialog) and set the lookup vie console fd.field("AssignedTicket").value = 105; the value will besaved as expected.
Seems to be an issue if opened in dialog.

OK I found the solution, it is here Managing common fields with JavaScript — SharePoint forms (plumsail.com)

Returns promise that is resolved when the field has fully loaded. Useful for executing scripts as soon as the field fully loads.

Only available for List or Library control, Person or Group, Lookup and Content Type SharePoint fields!

Example:

fd.spRendered(function() {
fd.field('User').ready().then(function(field) {
console.log(field.value);
// or
console.log(fd.field('User').value);
});

fd.field('ContentType').ready().then(function(field) {
    console.log(field.value);
    // or
    console.log(fd.field('ContentType').value);
});

});

1 Like