Logging a field change and recording
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
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
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.
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.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 16 guests