0

Have been writing some Client Side and it was going good but when I tried to make it more abstract I started getting some errors when debugging and have tried a million and one things and am left scratching my head any help welcome (Seems like an issue in the sp.js file and it blows-up when it gets to the ""g_Context = new SP.ClientContext.get_current();"" sectionn as well):

Web part page html page references:

<link rel="stylesheet" href="/_catalogs/masterpage/OTR/JQuery/JQ-UI-Full/jq-ui-1.11.4/base/jquery-ui.css" />  

<script type="text/javascript" src="/_catalogs/masterpage/OTR/jquery/jquery-1.12.3.js"></script>
<script type="text/javascript" src="/_catalogs/masterpage/OTR/jquery/jquery-ui.js"></script>

<script type="text/javascript" src="/_layouts/15/clienttemplates.js"></script>
<script type="text/javascript" src="/_layouts/15/clientforms.js"></script>
<script type="text/javascript" src="/_layouts/15/clientpeoplepicker.js"></script>
<script type="text/javascript" src="/_layouts/15/autofill.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.RequestExecutor.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script> 

<script type="text/javascript" src="/_catalogs/masterpage/OTR/New_OT_Request.js"></script>

Code:

g_spItemID = 0;
g_QStringID = 'ItemID';
g_WebAppUrl = 'http://sp2013dev/';
g_Context = '';
g_Web = '';
g_MainListName = 'OTR_Requests';
g_MainList = '';
g_CollListItems = '';
g_DivisionCollItems = '';
g_CurrentUser = 'domain\\user1';
g_ThankYouPage = g_WebAppUrl + 'SitePages/Thank_You.aspx';

$(
function () {
if (typeof (_spBodyOnLoadWrapper) != 'undefined') { _spBodyOnLoadWrapper();   }
ExecuteOrDelayUntilScriptLoaded(SetCurrentContext, "sp.js");
}
);

function SetCurrentContext()
{
g_Context = new SP.ClientContext.get_current();
g_Web = g_Context.get_web();
g_MainList = g_Web.get_lists().getByTitle(g_MainListName);
g_CurrentUser = g_Web.get_currentUser();

g_Context.load(g_CurrentUser);
g_Context.executeQueryAsync(Function.createDelegate(this, this.onCurrentContextSucceeded), Function.createDelegate(this, this.onCurrentContextFailed));

function onCurrentContextSucceeded(sender, args) {
    SetPeoplePicker_Multiselect('h_Employee_PeoplePicker', 0);
    SetPeoplePicker_Multiselect('h_Supervisor_PeoplePicker', 0);
    SetPeoplePicker_Multiselect('h_Overtime_Requestor_PeoplePicker', 0);

    SetRequestedDate_Calendar();

    setDivision_DDL();
    setPayPeriod_DDL();
    bindButtonClicks();
}

function onCurrentContextFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace() + '\n' + 'Please take a screen shot BEFORE clicking the OK button and notify your Systems Administrator');
    window.location.href = g_ThankYouPage;
}

}

Errors:

c_newDocCalloutWidth=parseInt(Strings.STS.L_NewDocumentCalloutSize);NewDocumentInfo=InitializeNewDocumentInfo();ComputedFieldWorker=function(){function h(c,d,a){if(c["Created_x0020_Date.ifnew"]=="1"){var b=GetThemedImageUrl("spcommon.png");

'Strings' is undefined

SP.UI.MenuTest.$g=null;SP.Utilities.Utility.layoutS_LATESTVERSION_RELATIVE_URL="_layouts/"+SP.OfficeVersion.majorVersion+"/";SP.Utilities.Utility.layoutS_LATESTVERSION_URL="/"

Unable to get property 'majorVersion' of undefined or null reference

[SP.ScriptUtility.isNullOrUndefined(a)?SP.ClientContext.$4v():a]);this.set_formDigestHandlingEnabled(true)};SP.ClientContext.$4v=function(){ULSdih:;var a=window._spPageContextInfo;if(a)return

Object doesn't support property or method 'set_formDigestHandlingEnabled'

2 Answers 2

0

Before calling function SetCurrentContext(), Try to add

 <script type="text/javascript">
        ExecuteOrDelayUntilScriptLoaded(SetCurrentContext, "sp.js");
        function SetCurrentContext()
        {//your code}

[Update]

It looks init.js is not loaded

if the issue still not working , try to reference all layout scripts as the following :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script>


   $(document).ready(function(){
        var scriptbase = "http://epm/workflow" + "/_layouts/15/";
    //Do not change the order, scripts should load by order.  
     $.getScript(scriptbase + "init.js",
            function () {
                $.getScript(scriptbase + "SP.Runtime.js",
                   function () {
                $.getScript(scriptbase + "SP.js", SetCurrentContext);
              });
          });
           });
// **add your code**


function SetCurrentContext()
{
}

function onCurrentContextSucceeded(sender, args) { }

function onCurrentContextFailed(sender, args) { }

</script>
7
  • I have it being called in doc load with jq: $( function () { if (typeof (_spBodyOnLoadWrapper) != 'undefined') {_spBodyOnLoadWrapper(); } ExecuteOrDelayUntilScriptLoaded(SetCurrentContext, "sp.js"); } );
    – Shane Gib.
    Commented Oct 4, 2016 at 20:15
  • NP, but Should you first try this ? , and also share your full code to can help you accurately Commented Oct 4, 2016 at 20:18
  • I updated that part of the code there is a lot of code and this is the section getting the errors is why I only added it
    – Shane Gib.
    Commented Oct 4, 2016 at 20:24
  • have you referenced the JQuery at the top of your script or master page ? <script src="ajax.googleapis.com/ajax/libs/jquery/1.12.4/…> <script> Commented Oct 4, 2016 at 20:27
  • I will add the html page references in above code
    – Shane Gib.
    Commented Oct 4, 2016 at 20:28
0

Unfortunately, thus far at least, the only way I can make these errors go away is to edit the web part page and add the following references in it serve side, instead of referencing them in the HTML page file that I link to in the content editor web part (text file link property) inside the web part page:

Removed from HTML page file:

<script type="text/javascript" src="/_layouts/15/clienttemplates.js"></script>
<script type="text/javascript" src="/_layouts/15/clientforms.js"></script>
<script type="text/javascript" src="/_layouts/15/clientpeoplepicker.js"></script>
<script type="text/javascript" src="/_layouts/15/autofill.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.RequestExecutor.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script> 

Edited/Added to Web part page (added between SharePoint:ScriptBlock and the SharePoint:RssLink tags):

<SharePoint:ScriptLink name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="clientforms.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="clientpeoplepicker.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="autofill.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.RequestExecutor.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.runtime.js" runat="server" LoadAfterUI="true" Localizable="false"/>

Obviously I don't like this solution b/c it forces me to customize the web part page from its original template... :( Any better suggested ways?

Thanks. SG.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.