Need a little help with some javascript in Sharepoint column values

Seven0fNine used Ask the Experts™
Hi, I am having a little trouble with some javascript to extract a user name from a Sharepoint column, verify that the user exists in a valid sharepoint group and then if true, to populate another field with 'Yes'... I am using the following Sharepoint columns in a New form:

User name                 William Smith
IT Support Group      Yes

What I would like to achieve is when someone enters a name in the 'User name' column, javascript to fire off to see if this user is in the following Sharepoint group 'IT Support'. If the user is part of this group then for 'Yes' to be automatically populate the column 'IT Support Group'.

I can validate the group for the 'logged in user'. However, I need help with the following:

1) fire off the javascript when a username has been entered in the User Name field and extract its value?
2) return 'yes' to the IT Support column (if user exists in IT Support group).

Below is the code I am currently using in Script Editor:

    <script src="" type="text/javascript"></script>
     <script language="javascript" type="text/javascript">
      $(document).ready(function() {
         var x = GetDept();
              alert (x);
                  $("input[Title='IT Support Group']").val(x);

function GetDept() {
	var url = _spPageContextInfo.webAbsoluteUrl +'/_api/web/currentuser/groups'
		$.getJSON(url, function (data) {
			$.each(data.value, function (key, value) {
				  if (value.Title == 'IT Support') {               
                                return 'Yes';             
 function getQueryString(key){
         var regex=new RegExp('[\\?&amp;]'+key+'=([^&amp;#]*)');
         var qs=regex.exec(window.location.href);
         return qs[1];


Open in new window

Thank you in advance for any help!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Zvonko זְאֵבSystems architect
Top Expert 2006

My advice is not to do that SharePoint Person and Group queries in JavaScript.
Can you do some calculated column SharePoint view and read that SharePoint list?

If you still want to do it in JavaScript then do it this way: read all memebers from your Group and lookup the searched User name.
The code for collecting all user names from a given Group ID is here:
var siteUrl = '/sites/MySiteCollection ';

function retrieveAllUsersInGroup() {

    var clientContext = new SP.ClientContext(siteUrl);
    var collGroup = clientContext.get_web().get_siteGroups();
    var oGroup = collGroup.getById(7);
    this.collUser = oGroup.get_users();

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded() {

    var userInfo = '';

    var userEnumerator = collUser.getEnumerator();
    while (userEnumerator.moveNext()) {
        var oUser = userEnumerator.get_current();
        this.userInfo += '\nUser: ' + oUser.get_title() + 
            '\nID: ' + oUser.get_id() + 
            '\nEmail: ' + oUser.get_email() + 
            '\nLogin Name: ' + oUser.get_loginName();

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial