Logging a field change and recording

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

30 Aug 2018

I'm looking to see if I can record changes to a date field and record the changes into a multiline field.

Ideally
old date -- Date changed - New date -- User. (Carriage return)

any changes to the date would then add a new line to this field.

I'm not sure if the form designer is the best method of recording this or if sharepoint designer would be a better solution

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

31 Aug 2018

Hi Roo,

You can do this by adding JavaScript code in JavaScript Editor from Forms Designer. First, make sure your Multiline Text Field is plain text. To do this you should go to the List Settings, choose your Field and choose property 'plain text'.

In the following, I will suggest you two examples of code you need.

The first example is useful in case when you need to save changes from Date Field right after a date was picked in the field.

var oldDate="";
fd.field('Date').control()._el().on('focusin', function(){
oldDate = fd.field('Date').value();
});

fd.field('Date').change(function(){
var change = fd.field('Change').value();
var date = fd.field('Date').value();
if (oldDate != "") {
fd.field('Change').value(change + oldDate + '--Date changed--'+ date + '--'+ _spPageContextInfo.userDisplayName + "\n");
}
});

The second example is useful in case when you need to save changes from Date Field after submitting a form.

var oldDate = fd.field("Date").value();
var changeFlag = false;
fd.field('Date').change(function(){
changeFlag = true;
});

fd.onsubmit(function() {
var change = fd.field('Change').value();
var date = fd.field('Date').value();
debugger;
if ((oldDate != "") && (changeFlag) && (date != oldDate)) {
fd.field('Change').value(change + oldDate + '--Date changed--'+ date + '--'+ _spPageContextInfo.userDisplayName + "\n");
}
return true;
})

Notice that 'Date' and 'Change' is the internal names of your Date Field and Multiline Text Field. You can find them in Forms Designer.

User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

27 Sep 2018

Perfect - Thank you

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests