Question

I am using the code here to dynamically open a link based on current user's email address. Is there a way I can use promoted link to accomplish the same?

I want a tile that says "Update Profile"

Was it helpful?

Solution

I found this site and attempted to combine both - seems to work so far...

$(function(){
var linkTitle = "";


$("a[id^='Tile_WPQ']").each(function(){
    $(this).attr("onclick","");
    $(this).attr("clickAction","");
    $(this).click(function (){

        linkTitle = $(this).find('li[title]').attr('id');

        switch (linkTitle){

            case  'Tile_WPQ4_1_6':
                var newRequestUrl = "https://xxx.sharepoint.com/teams/xxx/Lists/xxx/item/newifs.aspx";
                var options = {url: newRequestUrl, width: 700, height:600, title: "Submit New Request"};
                SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

                break;

            case  'Tile_WPQ4_2_6':
                var newProfileUrl= "https://xxx.sharepoint.com/Lists/xxx/Item/newifs.aspx";
                var options = {url: newProfileUrl, width: 700, height:600, title: "Create New Profile (New Staff Only)"};
                SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

                break;

            case  'Tile_WPQ4_3_6':
                    var currentUserEmail = _spPageContextInfo.userEmail;
                    var requestUrl = "https://xxx.sharepoint.com/_api/web/Lists/getByTitle('xxx')/Items?$filter=Title eq '" + currentUserEmail + "'&$select=Id";
                        $.ajax({
                            url: requestUrl,
                            method: "GET",
                            async: false,
                            headers: { "Accept": "application/json; odata=verbose" },
                            success: function (data) {
                                if(data.d.results.length > 0) {
                                    var editFormUrl= "https://xxx.sharepoint.com/Lists/xxx/EditForm.aspx?ID=" + data.d.results[0].Id;
                                    var options = {url: editFormUrl, width: 700, height:600, title: "Edit Your Profile"};
                                    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
                                }else {
                                    alert("Your profile not found. Create a profile."); }                   
                                },
                            error: function (data) { alert("Failed to load your profile");  }
                        });

                break;

            default:
                break;

        }
    })
})
});

</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top