none
would like to direct users to a specific site based on criteria

    Question

  • hi,

    in our organization, we would like to send users to their country specific sharepoint site automatically, hopefully based on what is already filled in in the country field on their o365 profile. The sites have country specific HR forms, policies, etc.

    is that possible and if so, can someone give me some direction to how to accomplish that?

    thank you

    Tuesday, August 16, 2016 6:51 PM

Answers

  • Hi mooseter,

    As Rajesh mentioned, you could use JavaScript to get user properties on the page in SharePoint Online. Then redirect the page based on the property value.

    Here is the code to get user properties in SharePoint Onlne:

    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.0.min.js"></script>   
    
    <script src="/_layouts/15/SP.Runtime.js"></script>   
    
    <script src="/_layouts/15/SP.js"></script>   
    
    <script src="/_layouts/15/SP.UserProfiles.js"></script> 
    
    
    <script type="text/javascript">   
    
      
    
    //debugger;   
    
    $(document).ready(function () {   
    
    // ensure that the SP.UserProfiles.js file is loaded before the custom code runs.   
    
    SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');   
    
    });   
    
    var userProfileProperties;   
    
    function loadUserData()    
    
    {   
    
    //debugger;   
    
    //Get Current Context     
    
    var clientContext = new SP.ClientContext.get_current();   
    
    //Get Instance of People Manager Class   
    
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);   
    
    userProfileProperties = peopleManager.getMyProperties();   
    
    clientContext.load(userProfileProperties);   
    
    clientContext.executeQueryAsync(onSuccessful, onFailure);   
    
    }   
    
    function onSuccessful (sender, args) {   
    
    //debugger;   
    
    //Get default properties   
    
    var username = userProfileProperties.get_displayName();   
    
    var desigination = userProfileProperties.get_title();   
    
    var pictureURL = userProfileProperties.get_pictureUrl();   
    
    //Get custom properties   
    
    var employeeID = userProfileProperties.get_userProfileProperties().EmployeeID;   
    
    alert(username + "/" + pictureURL + "/"  + employeeID + "/" + desigination);   
    
      
    
    }   
    
    function onFailure(sender, args) {
    
            alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
    
        }  
    
    </script> 

    For more information, you could refer the demo in the following article:

    http://www.c-sharpcorner.com/UploadFile/93cb27/get-user-properties-in-sharepoint-online/

    Best Regards,

    Linda Zhang


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

    Wednesday, August 17, 2016 9:24 AM

All replies

  • Add a script editor on your site home page and then use the below REST Api to get the current user's country and based on that redirect to respective site.

    http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=property_country 


    ---
    Rajesh
    rjesh.com| @rjesh
    You don't need to buy me a beer, if helpful just smile, vote, and mark it as answer.

    Wednesday, August 17, 2016 1:49 AM
  • You can try the below scenario as well

    https://social.technet.microsoft.com/Forums/en-US/81a8eb83-5046-4508-83fe-fff02643d024/redirect-visitor-to-regional-specific-home-page-in-sharepoint-2010-iis-7?forum=sharepointgeneralprevious


    Please remember to click Mark as Answer on the answer if it helps you

    Wednesday, August 17, 2016 5:42 AM
  • Hi mooseter,

    As Rajesh mentioned, you could use JavaScript to get user properties on the page in SharePoint Online. Then redirect the page based on the property value.

    Here is the code to get user properties in SharePoint Onlne:

    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.0.min.js"></script>   
    
    <script src="/_layouts/15/SP.Runtime.js"></script>   
    
    <script src="/_layouts/15/SP.js"></script>   
    
    <script src="/_layouts/15/SP.UserProfiles.js"></script> 
    
    
    <script type="text/javascript">   
    
      
    
    //debugger;   
    
    $(document).ready(function () {   
    
    // ensure that the SP.UserProfiles.js file is loaded before the custom code runs.   
    
    SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');   
    
    });   
    
    var userProfileProperties;   
    
    function loadUserData()    
    
    {   
    
    //debugger;   
    
    //Get Current Context     
    
    var clientContext = new SP.ClientContext.get_current();   
    
    //Get Instance of People Manager Class   
    
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);   
    
    userProfileProperties = peopleManager.getMyProperties();   
    
    clientContext.load(userProfileProperties);   
    
    clientContext.executeQueryAsync(onSuccessful, onFailure);   
    
    }   
    
    function onSuccessful (sender, args) {   
    
    //debugger;   
    
    //Get default properties   
    
    var username = userProfileProperties.get_displayName();   
    
    var desigination = userProfileProperties.get_title();   
    
    var pictureURL = userProfileProperties.get_pictureUrl();   
    
    //Get custom properties   
    
    var employeeID = userProfileProperties.get_userProfileProperties().EmployeeID;   
    
    alert(username + "/" + pictureURL + "/"  + employeeID + "/" + desigination);   
    
      
    
    }   
    
    function onFailure(sender, args) {
    
            alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
    
        }  
    
    </script> 

    For more information, you could refer the demo in the following article:

    http://www.c-sharpcorner.com/UploadFile/93cb27/get-user-properties-in-sharepoint-online/

    Best Regards,

    Linda Zhang


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

    Wednesday, August 17, 2016 9:24 AM