Skip to main content
TitleCommentModifiedModified By
Test1Test1Comment6/6/2016  10:00:12 pmuser1
Test2Test2Comment7/6/2016  10:00:12 pmuser2
Test3Test3Comment9/6/2016   01:00:00 pmuser3
Test4Test4Comment11/6/2016  11:00:17 pmuser4

Hi ,

I have a nintex form with a repeating control having multiple rows. I want to track which user had done the update i.e. as in above table. I tried using the parameters "CurrentUser" and "Date" but it is modifying all the rows. How can I handle it?

Hi,

Could you trap the row added/deleted events in script and handle it that way?

    NWF.FormFiller.Events.RegisterRepeaterRowAdded(function () {      
     });

     NWF.FormFiller.Events.RegisterRepeaterRowDeleted(function () {     
     });

Jan


If that doesn't work try this.  It should change the text field every time either comment or title is changed.

Add a calculated column outside the repeating section set to currentuser.  Store the Client ID in JS variable as currentUser

inside the repeating section add a calculated column with this formula:  user(currentRowNumber() , comment, Title) where comment and Tile are the names of the text boxes in the repeating section.

Add a text box with a css class userName.

Repeating section CSS class: myrepclass

Then paste this in JS




  function user(rowNum, value, valueTitle) {
  repeatingSection = NWF$('.myrepclass');
if (value != "" || valueTitle != ""){
   var currentUse = NWF$('#' + currentUser).val();


   NWF$(".myrepclass .nf-repeater-row").each(function(index){
  
    var $row = NWF$(this);    if( index  == rowNum) {
      $row.find(".userName input").val(currentUse);    }
   
   });
}
}

You can hide calculated column in CSS with display: none;


I have done the following steps:

  1. Added a calculated column outside the repeating section ad in formula I mentioned currentuser.  Store the Client ID in JS variable as currentUser  and I am getting the value of logged in user.
  2. Inside the repeating section add a calculated column with this formula:  user(currentRowNumber() , comment, Title) where "comment" and  "Title" as named controls .
  3. Add a text box with a css class username inside the repeating control/ also tried by adding that inside the repeating control also tried by giving username as  css class as well as css control class
  4. Repeating section CSS class: myrepclass.

Following are the issues:

  • Calculated value in the repeating control is showing #Value.
  • The textbox is showing the value of the "Current User"  for  all the rows and the value gets updated after the execution of javascript.Whereas in a particular row I want to show user who has modified the row last time. i.e it should not update  the values for  all the rows of  "Modified by" column in my example.
  • The statement  $row.find(".userName input").val(currentUse);    is executing for all the rows

1.  Once you get it fixed and working add a css class to the calculated column like hideMe.  then add this in the CSS

.hideMe {

display: none;

}

2.  add an alert in different places to see what is happening when you change the value.

After if( index  == rowNum) {  add this

alert(index);

alert(rowNum);  see what is happening.  it should only alert you when the rowNum from your function and index from for each are equal.

Did you make sure the css class is userName?

Paste from your form the JS bake to here to make sure it copied correctly.


Hi,

I have added the alerts and the script seems to be executing as " userName" textbox is showing the value of currentuser.

Since         $row.find(".userName input").val(currentUse) takes the value from the calculated "currentuser field it changes dynamically depending upon the currentuser and the textboxes in all the rows shows the value of currentuser.I am getting the correct value of rownum but the values of currentuser gets updated


This should only change the row that you modified a field in.  If you put the alerts after the If statement, you should only get 2 alerts and it should be the current row number.

You are only wanting to update one row correct?


The script is also getting executed on the page load due to which it is overwriting all the values. How can I avoid the script execution on page load?


Ah, forgive me, I cheated on my testing,  I see the problem now.  add two more single line text boxes in your repeating row with these properties

CSS class:  comment hideMe  ........ JS variable:  commentTwo

CSS class:  title hideMe    ................JS Variable:  titleTwo

Then replace your JS with this.  This will compare the title and comment to previous values.  If the same nothing happens...if different it will update the hidden text box and the username.

var valueT = NWF$('#' + commentTwo).val();

var valueTitleT = NWF$('#' +titleTwo).val();

  function user(rowNum, value, valueTitle) {

  repeatingSection = NWF$('.myrepclass');

if (value != valueT || valueTitle != valueTitleT){

alert("this ran");

   var currentUse = NWF$('#' + currentUser).val();

   NWF$(".myrepclass .nf-repeater-row").each(function(index){

  

    var $row = NWF$(this);    if( index  == rowNum) {

      $row.find(".userName input").val(currentUse);

      $row.find(".comment input").val(value);

$row.find(".title input").val(valueTitle);

     }

   

   });

}

}


Its failing in case of multiple rows.In case I have 4 rows and i am updating the third so on next page load it will update the textbox value of first two rows.For testing purpose I am binding currenttime instead of current user.The reason is that on page load it is taking the "valueTitleT " and "valueT" of the last row. I also got the same issue regarding the row instance  when I tried to apply JavaScript attribute to the repeating section control, Its getting applied only on the last row control


Parker Petty​ Thanks for your help.

What I did is once the user updates the comment at particular row I will make that row read only and by using below script I can update the particular row in which update take place .I have used a javascript to make rows visible to user according to some query string value so that one user can update only one row. But it will be better If you or me find the solution

  function user(rowNum, value, valueTitle) {

  repeatingSection = NWF$('.myrepclass');

if (value != valueT || valueTitle != valueTitleT){

alert("this ran");

   var currentUse = NWF$('#' + currentUser).val();

   NWF$(".myrepclass .nf-repeater-row").each(function(index){

  

    var $row = NWF$(this);    if( index  == rowNum) {

var checkvalue=$row.find(".userName input").val();

if(checkvalue !=" ")

{

if(checkvalue!=currentuse)

{

      $row.find(".userName input").val(currentUse);

      $row.find(".comment input").val(value);

$row.find(".title input").val(valueTitle);

     }

}

if(checkvalue==" ")

{

   $row.find(".userName input").val(currentUse);

      $row.find(".comment input").val(value);

$row.find(".title input").val(valueTitle);

}

}

   

   });

}

}


So I think I found a better solution.  same code I just added two variables to the function. .. add them in the calculated value:  user(currentRowNumber() , comment, Title, comment2, Title2)....only thing I see is when a new row is added it doesn't populate the username field, but it does when you modify a field in the row.

function user(rowNum, value, valueTitle, valueT, valueTitleT) {

   repeatingSection = NWF$('.myrepclass');

if (value != valueT || valueTitle != valueTitleT){

   var currentUse = NWF$('#' + currentUser).val();

   NWF$(".myrepclass .nf-repeater-row").each(function(index){

  

    var $row = NWF$(this);    if( index  == rowNum) {

      $row.find(".userName input").val(currentUse);

      $row.find(".comment input").val(value);

$row.find(".title input").val(valueTitle);

     }

   

   });

}

}


Parker Petty​ Thanks a lot for your help. According to the requirement the comment is to be modified only once so I am able to achieve that with my above code.


Another way to accomplish this without JavaScript is to use a calculated value field for the "Modified By" column called "ModifiedByUser" and for the formula add:

if(ModifiedByUser=="", Current User(Display Name), ModifiedByUser)

Same logic could be done with Modified as well. Works on SPOnline.

 


Reply