Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS heirachy from Sharepoint list

    Hi all

    I'm fairly new to Js and still learning and disecting code etc..

    Basically we have a prebuilt template on share point aspx that someone created a long time ago and now they've left. It creates a heirarchy chart from a share point list. Looking at the file its made up of JS so I've copied it and changed the list name it pulls from but I can't get it to work. I think the problem is that I'm not calling it or something.

    Please could someone help!!!!!
    Its pulled into sharepoint via an iframe so none of the code is touched.


    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript">

    var Name = "x";
    var Photo = "x";
    var ExtNo = "x";
    var RoleDescription = "x";
    var ChampText = "x";
    var StatusText = "x";
    var TopRow = "x";
    var SecondRow = "x";

    var TeamMemberPhoto = "x";


    // Function to get sharepoint list

    function getListStructureChart(){

    $().SPServices({
    operation: "GetListItems",
    listName: "Team_Members_Carolyn", // Name of your list
    async:false,

    completefunc: function(xData, Status) {

    $(xData.responseXML).find("z\\:row").each(function(){

    // Set values to those of the Team Members List -->

    Name = $(this).attr("ows_Name");
    Photo = $(this).attr("ows_Team_x0020_Member_x0020_Photo");
    ExtNo = $(this).attr("ows_Ext_x002e__x0020_No");
    RoleDescription = $(this).attr("ows_Title");
    ChampText = $(this).attr("ows_Champion_x0020_text");
    StatusText = $(this).attr("ows_Status_x0020_text");
    TopRow = $(this).attr("ows_Team_x0020_Leader_x0020_Row");
    SecondRow = $(this).attr("ows_Second_x0020_row");




    // Remove Undefined values -->

    if (ExtNo == undefined) {Extno =""};
    if (RoleDescription == undefined) {RoleDescription =""};
    if (ChampText == undefined) {ChampText =""};
    if (StatusText == undefined) {StatusText =""};


    // Set path to photo -->

    Photo = Photo.replace(/[0-9]/g, '');
    Photo = Photo.substring(2, Photo.length);

    TeamMemberPhoto = ('/sites/thinktank/Team_Members/' + Photo + '.png');


    // Remove random characters -->


    Name = Name.replace(/[0-9]/g, '');
    Name = Name.substring(2, Name.length);


    // Fill in DIVS -->

    if (TopRow == "1") {

    $( '<div class="Structure_Chart_Team_Member"><img class="Structure_Chart_Team_Member_Photo" src="' + TeamMemberPhoto + '" /><p><a id="replaceme">' + Name + '</a></p><p>' + RoleDescription + '</p><p class="Structure_Chart_ChampionText">' + ChampText + '</p><p class="Structure_Chart_StatusText">' + StatusText + '</p><p class="Structure_Chart_ExtNo">' + ExtNo + '</p></div>' ).appendTo( '#Structure_Chart_Top_Row' );

    }

    else if (SecondRow == "1") {

    $( '<div class="Structure_Chart_Team_Member"><img class="Structure_Chart_Team_Member_Photo" src="' + TeamMemberPhoto + '" /><p><a id="replaceme">' + Name + '</a></p><p>' + RoleDescription + '</p><p class="Structure_Chart_ChampionText">' + ChampText + '</p><p class="Structure_Chart_StatusText">' + StatusText + '</p><p class="Structure_Chart_ExtNo">' + ExtNo + '</p></div>' ).appendTo( '#Structure_Chart_Second_Row' );

    }

    else {

    $( '<div class="Structure_Chart_Team_Member"><img class="Structure_Chart_Team_Member_Photo" src="' + TeamMemberPhoto + '" /><p><a id="replaceme">' + Name + '</a></p><p>' + RoleDescription + '</p><p class="Structure_Chart_ChampionText">' + ChampText + '</p><p class="Structure_Chart_StatusText">' + StatusText + '</p><p class="Structure_Chart_ExtNo">' + ExtNo + '</p></div>' ).appendTo( '#Structure_Chart_Third_Row' );

    }

    // Now that the Team member div has been created, update the ID of the hyperlink and add the mailto link.

    $('a#replaceme').attr('href', 'mailto:' + Name);
    $('a#replaceme').attr('id', Name);




    });

    $( '<div class="clear"></div>' ).appendTo( '#Structure_Chart_Top_Row' );
    $( '<div class="clear"></div>' ).appendTo( '#Structure_Chart_Second_Row' );
    $( '<div class="clear"></div>' ).appendTo( '#Structure_Chart_Third_Row' );

    }
    })
    } // end function

    $(document).ready(function() {

    getListStructureChart();

    $('.ms-vb a').each(function(){

    if ($(this).text() == "(More Events...)") {

    $(this).attr('href', 'Team_Calendar.aspx');

    }
    });

    // Handler for .ready() called.

    });


    </script>
    </body>
    </html>

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    if you used all the code shown here the code should be calling itself on dom ready.a few thigns that could be an issue

    1. you have the list name incorrect, double check the internal list name, they tend to keep the same name even after the "display" name of the list has been changed, maybe it was altered at some point.

    2. the new list doesnt have the exact same field names




    side note, when using custom js in sharepoint, its better to include the code in an external file on the SP site, then link to the file in a content editor webpart and link to the js file. you appear to have this as an entire html document when it shoudl really only be part of the document it is being included in.

    Are you getting any javascript errors??
    Last edited by DanInMa; 12-13-2013 at 03:24 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Dna, thanks for your suggestion.

    I've removed the html head etc. tags and just kept the Javascript within the tags and saved it as a HTML file.

    I've loaded this into a content editer but stil lno results.
    I double checked the list name and changed this as well as it didn't change the core name when I amended it previously. Still no results.

    I can't work out what I'm doing wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •