Solved

Click Button to add current user object to person or group field

  • 10 January 2017
  • 5 replies
  • 118 views

Badge +4

Hello!

 

I am creating an event sign up form through Nintex Forms for Office 365 / Sharepoint Online. My issue is that I want to make a sign up button that a user can click when viewing the form and it will populate the attendees field (person / group column; accepts multiple) with a user object like in the picture below.

 

197542_pastedImage_1.png

 

Is there a quick and easy way to do this in javascript or in field settings? I do want it to show as an person object as it will then be saved back to the Attendees column as a person and not just a text of the user's display name.

*Edit* I don't want to this to be on load, the end user will be viewing the form and deciding if they want to join this event or not. **

 

Any ideas? I'm fairly new to Nintex / Office 365 / Sharepoint Online, feel free to correct me if I'm going about things the wrong way.

 

Thanks,

 

-Trang

icon

Best answer by tphan 20 March 2017, 18:52

View original

5 replies

Userlevel 6
Badge +15

I have a question .. why would you need to add their name to this at all? What if, instead, there's a checkbox that says "I want to attend!" and when that checkbox = true, it adds "Current User" into whatever field you need it in?

It just seems strange to me to display it like this instead of having a standard "I want to attend!" checkbox.

Otherwise, it would basically be an onClick event I suppose! I'll wait for you to strike down my previous idea...

Badge +4

‌, Thanks for the response!

I'd love if it I was the designer behind how the functionality worked here but it was requirement from my end user. I've worked out a solution through workflow, though I was trying to avoid having to use it in the first place.

Current User for me appears to be bugged that it doesn't always populate a field (especially if it's hidden) on edit. I'm not sure if I should delete this question as I've decided on a different work around, but there isn't technically a solution that I've found for this specific idea.

Userlevel 7
Badge +17

Hey ‌ - can you mark your answer as correct or Rhia's? Have you solved the issue?

Regards,

Tomasz

Badge +4

The issue is unresolved for me at this point, as I've had to implement many one-off solutions in order to achieve my original goal.

At this point I've implemented javascript in order to bypass view mode and bring the user straight to edit mode. On the "Sign-Up" button I've initiated a workflow to gather any users from the attendees field and then add (login name-string) to the collection, delimit the string with a semi-colon and then update the attendees field.

I'd still like to know if this could've been achieved without having to create a workflow for this.

Badge +4

After leveraging (and learning CSOM) for Sharepoint, I've been able to solve this issue. Please see the code below if you are trying to accomplish this as well. I'm using it currently in an Event Sign-Up application on my intranet.

function addPerson() {

var oListItem = getCurrentItem();
var users = new Array();


NWF$('.ip-item span div:not(.ip-close)').each(
function() { 
users.push(SP.FieldUserValue.fromUser(this.innerHTML));
}
);
users.push(SP.FieldUserValue.fromUser('Current User (Display Name)'));
oListItem.set_item('_x0023__x0020_Signed_x0020_Up', users.length);
oListItem.set_item('testChoice', 1);
oListItem.set_item('Attendees', users);
oListItem.update();


clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededAdd), Function.createDelegate(this, this.onQueryFailed));
}


function onQuerySucceededAdd() {
alert('You have been added to the list.');
location.reload();
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '
' + args.get_stackTrace());

}

function getCurrentItem() {

var oList = clientContext.get_web().get_lists().getByTitle('List Name');
this.oListItem = oList.getItemById(ID);
return oListItem;

}

And the opposite to this (remove person) is as follows

function removePerson() {


var oListItem = getCurrentItem();
var users = new Array();
NWF$('.ip-item span div:not(.ip-close)').each(
function() { 
if (this.innerHTML != 'Current User (Display Name)') {
users.push(SP.FieldUserValue.fromUser(this.innerHTML));
}
}
);

oListItem.set_item('Attendees', users);
oListItem.set_item('_x0023__x0020_Signed_x0020_Up', users.length);
oListItem.set_item('testChoice', 2);
oListItem.update();


clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededRemove), Function.createDelegate(this, this.onQueryFailed));
}


function onQuerySucceededRemove() {
alert('You have been removed from the list.');
location.reload();
}

Reply