0

I just started working at a new place as software developer and they have put me on a project that needs to be improved as a way to get me started.

It's a sharepoint 2010 project and it's made up of C# and ASP. I have little experience at all in developing for sharepoint so I would like to ask for some assistance if possible. Basically they have a page with a lot of activies and each activity is supposed to try and save the company money.

Now, when you press "Edit item" a JavaScript executes and styles some of the table that is presented to you. Since this project was made in a rush there is no documentation and there are hard coded values. What I wanted to try first was to change the year numbers it displays as these are hard coded in. So I'd go from this:

var quarters = {
    "Q3": {
        title: "Q3",
        name: "Q3 (MAR-MAY)"
    },
    "Q4": {
        title: "Q4",
        name: "Q4 (JUN-AUG)"
    },
    "2015-16": {
        title: "2015-16",
        name: "Budget year 2015/2016"
    },
    "2016-17": {
        title: "2016-17",
        name: "Budget year 2016/2017"
    }
};

to this:

function getCurrentYear() {
    var year = new Date().getFullYear();
    return year;
}

var quarters = {
    "Q3": {
        title: "Q3",
        name: "Q3 (MAR-MAY)"
    },
    "Q4": {
        title: "Q4",
        name: "Q4 (JUN-AUG)"
    },
    "CurrentYear-NextYear": {
        title: getCurrentYear + "-" + (getCurrentYear()+1).toString().substr(2,2),
        name: "Budget year" + getCurrentYear() + "/" + getCurrentYear()+1
    },
    "NextYear-YearAfterNextYear": {
        title: (getCurrentYear() + 1) + "-" + (getCurrentYear() + 2).toString().substr(2, 2),
        name: "Budget year " + (getCurrentYear() + 1) + "-" + (getCurrentYear() + 2)
    }
};

But when I deploy the sharepoint site and use the "Edit Items" part, nothing that the JaveScript is supposed to do happens. I tried to debug but the debugger never actually enters the function that I try to use which leads me to believe that the website never uses the JavaScript in the first place.

My question is: Where would I check for a possible use of the script?

I searched throughout the entire solution and nowhere is the JavaScript file referenced but it works fine on production and the Revision History reveals nothing that would break the usage of the JavaScript.

4
  • If this script isn't loaded, it can't right. Find out how it gets loaded in production, and do the same thing for your test. Commented Nov 5, 2015 at 13:59
  • Yeah that's what I'm trying to do but it seems that since the project was made and uploaded as a site feature, it has been changed through Sharepoint rather than code so I have two very different versions of the same feature. Commented Nov 5, 2015 at 14:06
  • @Vipar You're missing parentheses after getCurrentYear in one of your function calls. Commented Nov 5, 2015 at 14:07
  • @Thriggle Thanks for noticing! :) Commented Nov 5, 2015 at 14:08

2 Answers 2

2

throughout the entire solution and nowhere is the JavaScript file referenced

since you mentioned that this was done in a rush maybe the script reference was added in the aspx after the page was deployed? (this is an extremely dirty way to do things but not the worst i've seen in a sharepoint context)

to check this: on the server, look for the aspx at the deployment location (usually something like: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\<ProjectName>\ ) and see if the script file is referenced in the application page there.

it could also be that another script file on the page has been modified in the hive which is loading the target script file: i'd check the script files in the hive for calls like SP.SOD.execute, executeFunc and EnsureScriptFunc or just SP.SOD.(besides looking for the file name obviously)

also: the script might be added via a different solution(if there are any) as delegate control so that might be another thing to check if you can get the source for that.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your suggestion. Me and another colleague figured it out. It appears that the script was applied on the forms specifically, by going to the sharepoint page, go to the site where the form is, press List Tools and enter List. Then press "Form Web Parts" and add a Web Part if none exist. Then you can edit the web form and add a script tag in there and add the script...very dirty.. <_<
0

To debug JavaScript, hit F12 to bring up the browser's developer tools, including the JavaScript console. Then you generally have to refresh the page to get the code to run again.

You'll only be able to see errors generated by code that actually gets executed, so if you don't see any errors, your code may not be running.

You can also use the JavaScript console to type in part or all of your code manually to see what works and what doesn't work.

I noted in a comment that there seems to be a missing set of parentheses after one of your calls to getCurrentYear but without the full code I can't guarantee that's the only problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.