Is there an equivalent of {CurrentItem} token in 'old' Forms Designer

Hi,

Am looking at using the ID of the item dynamically to update other fields in my form. I see that you are now able to bind new related items/documents in a new parent form, however this does not use the same {CurrentItem} token that used to bind new parents to new child items.

Is there an equivalent ‘token’ that I can use for dynamically assigning the ID to other field values on a new item?

Kind regards
Andy

Dear Andy,
Are you talking about List or Library control? There is no such token, but it can be achieved with JS. Are you talking about Child List or Child Doc Library? The implementation would be different for different cases.

Hi Nikita,

Ideally I’d like to be able to achieve this for both list and library configurations, if you can point me in the right direction that would be much appreciated.

Thanks
Andy

Dear Andy,
The examples I’ll give here will only work with Edit or Display Form, since New Form doesn’t have an Id yet, though it will work with other fields on the form, if they are already filled in.

For Document Library, it’s enough to use the following code:

fd.spRendered(function() {
    fd.control('ChildDocs').$on('filesUploaded',
        function(itemIds) {
            //get document library
            var library = pnp.sp.web.lists.getByTitle(fd.control('ChildDocs')._listUrl);
            //go through each uploaded Item Id and set Title (or other fields)
            itemIds.forEach(function(itemId) {
                library.items.getById(itemId).update({
                    Title: fd.itemId,
                    Field2: fd.itemId
                });
            });
            //refresh List or Library after delay, so values are displayed properly
            setTimeout(function() {
                  fd.control('ChildDocs')._dataProvider.refresh();
            }, 2000);
    });
});

For Child List, you will need to add the following line to JS code on the Parent Form:

window.fd = fd;

This will allow you to retrieve values from dialog window. So, if you add code like this to Child Item, it will automatically populate its fields:

if (window != window.top && window.top.fd) {
    fd.spRendered(function(){
        var id = window.top.fd.itemId;
        if(id){
            fd.field('Title').value = id;
        }
    });
}