none
Can I convert usernames inside security groups into dropdown choices RRS feed

  • Question

  • I am facing this issue inside SharePoint server 2013 on-premise, where I have the following requirement, but not sure which approach I can follow to implement it:-
    1. We have a tracking list which has 2 fields of type choices; one named “Approver”, the second named “Status”.
    2. We have 3 security groups named ; Initial-Approver, Med-Approver, Final-Approver.
    3. The Status choices are equal to the security groups names (which are Initial-Approver, Med-Approver, Final-Approver)
    4. Now I want to implement this scenario using JavaScript or custom code:-
      1. When a user creates a new tracking item, I want the Approver drop-down choices to be equal to the users inside the Initial Approver security group.
      2. When editing the tracking item, I want to implement these scenarios:-
        1. If the user changes the status from initial-approver to let say final-approver, then the choices of the drop down should be the users inside the final-approver group, as so on….

    So mainly I want to know how I can achieve these 2 points to be able to complete the above task:-

    1. How to dynamically get the users inside the groups based on users selection for the status field.
    2. If I can achieve the above then I will need to find a way to convert the retrieved usernames to choices inside the drop down list.

    So can anyone help me in achieving this requirement, as I could not find any useful info which can help me in achieving this .

    Thanks

    Thursday, February 16, 2017 2:04 PM

All replies

  • Hi,

    To get the users from AD security groups, we can create a custom rest service and use  SPUtility.GetPrincipalsInGroup method to achieve it. Then consume the rest api using jQuery Ajax.

    To add the choice value into the choice field, we can use JSOM to achieve it.

    function updateProduct() {
    	var context = new SP.ClientContext.get_current();
    	var web = context.get_web();
    	var cldList = web.get_lists().getByTitle("ChoiceFeild");
    	var categoryField = cldList.get_fields().getByInternalNameOrTitle("Visa");
    	var categoryChoiceField = context.castTo(categoryField, SP.FieldChoice);
    	context.load(categoryChoiceField);
    	context.executeQueryAsync(function ()
    	{
    		var categoryChoices = categoryChoiceField.get_choices();
    		var categoryTC = categoryChoices.filter(function (choice)
    		{
    			return choice === "Dependent Visa";
    		});
    		if (categoryTC.length == 0)
    		{
    			categoryChoices = new Array();
    			categoryChoices.push("Dependent Visa");
    			categoryChoiceField.set_choices(categoryChoices);
    			categoryChoiceField.updateAndPushChanges();
    			context.executeQueryAsync(function () {alert('done'); }, function () {alert('failed'); });
    		}
    	}, function () { alert('failed');});
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Friday, February 17, 2017 8:06 AM
    Moderator