0

I have a piece of code using SPUtility on the same page. I try both version on the same line:

version A result: Unable to get a SPField named FieldA

...
$(document).ready(function () {
    var SPFA = SPUtility.GetSPField('FieldA');
...
});

At first I suspect the SPUtility didn't load completely when the document.ready() run. so i try to change the document.ready() to window.load(), but it still not working.

I accidently use a SPUtility.HideSPField() function before this piece of code, and magically, it work! Why???

version B result: work fine.

...
SPUtility.HideSPField('FieldB'); //magic that make the code work?!
$(document).ready(function () {
    var SPFA = SPUtility.GetSPField('FieldA');
...
});

Anyone have any idea what might be the cause?

  • It's always worked for me. When you say it's not working, are you getting that as an error? Are you expecting the value in SPFA or the object? – mannaggia May 23 '17 at 2:25
  • On code version B, i get the SPField which i expected. But on the code version A, i did not get the SPField, it return "Unable to get a SPField named FieldA". – YHTAN May 23 '17 at 3:25
0

The SPUtility file might not be loaded when the document is ready. You can try one of the following ways to execute the function always


$(window).load(function(){
//your code
});

or you can push your function to queue as follows


function myFunction(){
//your code
}

You can refer this article for complete explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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