Default Column Value not appearing in Form, and unable to run Async PnP in BeforeSave

HI, appear to be having two issues.

I have a default value in my Title column, but when I open a new form, the default value is not populated. Is this by design?

In my spBeforeSave function, I have two PnP calls (one is a list item GET, one is a list Item UPDATE) the GET call gets a value from another list, which I then use to populate the Title field, however after saving the field is blank. I have something like the below:

sp.web.lists.getByTitle(‘MASTER_ID’).items.getById(1).get()
.then(function(item){
var projNumber = window.top.fd.field(‘Title’).value; //get value from parent form, this one is in dialog
var settingNumber = item.SettingValue; //set my value from the item I got
var invNumber = ‘INV-’ + projNumber + ‘-’ + settingNumber; // concatenate string
invNumber = invNumber.toString(); // make sure its a string
fd.field(‘Title’).value = invNumber; // set title field
});

After this another call updates the same item in the MASTER_ID list, but I removed that for the time being as I thought it might have been causing the field to blank out, but same behaviour is observed whether I do or not.

It would appear that the function above is somehow blanking the field, however when I debug this function it works ok, right until the moment the item is saved. Can you advise what I’m doing wrong?

Dear Andy,

I’m not sure now, what can be a cause of the issue, the code seems fine. Could you try to remove PnP calls to test if default value will be populated normally?

Hi Alex, I’ve just tried it without the PnP code and the default value set in the list appears to update the item. I then dropped the code back in and although my ‘new’ number shows up in the title field as it is saving, it then reverts to the default value in the parent list control. I thought maybe it was a timing issue but refreshing the control kept the same default value.

I’ve added other updates to field values in the (child) form in the fd.spBeforeSave handler, they seem to work,only the Title field does not update for some reason.

Dear Andy,

It seems the issue appears only in IE, we are researching it.

I can report that I have this issue in Chrome, Firefox and Edge, so perhaps my issue is different? Regardless of browser, the spBeforeSave handler appears to revert any of my updates to the default value in the Title field. I will try a straightforward, non-PnP update and see if this is any different, to establish if the issue is due to the asynchronous operation. I’ve posted this on both feeds FYI.

Dear Andy,

Please try to add this code:

fd.spBeforeSave(function(spForm) {
     ....
     return fd._vue.$nextTick();
});

Hi Alex,

I’m afraid that appears to make no difference, I still get the same behaviour. Should I put the return line within the PnP function??

Dear Andy,

Please try to change the code like this:

fd.spBeforeSave(function(spForm) {  
    return sp.web.lists.getByTitle("ListName").items.get().then(function(items) {
                .....
                return fd._vue.$nextTick();
            });
});

Hi Alex,

Eventually got to try this out. That works well, thanks for posting.

Regards
Andy