Jump to content

Add/Remove Name From List On Button Click


Recommended Posts

I've got a workflow going where when a logged in user clicks a 'Join' button on a specific record, their name will be added to a 'Help List'.

The 'Help List' field is a text(255). The Join button goes to an auto-submitting Single Record Update. The script was working fine with just adding names to the list.

However, I would like to add another button alongside 'Join' that will do the opposite - get the user's name from Auth, search the string for their name, and remove it from the Help List field if there is a match. 

document.addEventListener('DataPageReady', function(){
  var list = document.getElementById("EditRecordHelp_List");
  var iD = '[@authfield:Employee_Table_Alias]';
  var joinList = document.getElementById("cbParamVirtual1");

  if(list.value == '' && joinList.value == 'Y'){
    list.value = iD;
  } else if(list.value != '' && joinList.value == 'Y'){
    list.value = list.value + '; ' + iD;
  } else if (list.value != '' && joinList.value =='N'){
    var ret = list.replace(iD, '');
  }
});

My idea is to have a virtual field checkbox on the Single Record Update form. When the 'Remove From List' button is clicked, it will also send a parameter of either Y/N to the SRU form. That is what joinList variable is for. Right now as is, the first two if statements are running, but they are ignoring the joinList condition. If Help List is blank, it will just add iD. If it isn't, it'll add '; ' + iD, no matter if the checkbox is checked or not.

Link to comment
Share on other sites

Thanks, @TellMeWhy. That made most of the script work. Now nothing is added when Virtual1 = 'N'.

However, I am struggling with the 'remove from list' part. First, I was getting an error, because I was referring to the variable and not the value of the variable. Fixed that, no more error. But, there's also no deleting happening. Below is my most recent attempt. I'm not sure if the replace function is written correctly, but I'm not getting any errors. 

  if(list.value == '' && joinList.value == 'Y'){
    list.value = iD;
  } else if(list.value != '' && joinList.value == 'Y'){
    list.value = list.value + '; ' + iD;
  } else if (list.value != '' && joinList.value =='N'){
    list = list.value.replace(iD, '');
    return list;
  }
});

 

Link to comment
Share on other sites

The following should delete the matching iD and the extra ' ;' from the list if there is one.

  if(list.value == '' && joinList.value == 'Y'){
    list.value = iD;
  } else if(list.value != '' && joinList.value == 'Y'){
    list.value = list.value + '; ' + iD;
  } else if (joinList.value == 'N'){
    list.value = list.value.replaceAll('; ' + iD, '');
    list.value = list.value.replace(iD, '');
  }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...