1

I keep getting an error every time I am trying to insert some jquery/sputility code to get a SharePoint form field to be hidden if certain conditions are met. The error is "Unable to get SPField named ExternalSales". Here is the code:

<script src="<sharepoint site>/test/Shared Documents/jquery-3.1.1.min.js"></script>
<script src="<sharepoint site>/test/SiteAssets/sputility.js"></script>
<script>
$(document).ready(function () {
var externalsales = SPUtility.GetSPField('ExternalSales');
var showOrHideField = function() {
var externalsalesValue = externalsales.GetValue();
if (externalsalesValue == 'No') {
SPUtility.HideSPField('PPE');
}
else {
SPUtility.ShowSPField('PPE');
}
};
showOrHideField();
$(externalsales.Dropdown).on('change', showOrHideField);
});
</script>

With regards to the SPUtility syntax, how do I find out the strFieldName? I'm assuming that's the part that's incorrect.

Any help with this would be much appreciated.

0

I'm assuming that's your filed Display Name, may be you need to use External Sales (with a space)?

UPD:
There is also a method SPUtility.GetSPFieldByInternalName, if you know the internal name, this approach is preferable over display name.

  • I tried both, but I'm still getting the same error. Just a little more information, I am using a script editor web part on the same page as the SharePoint form. Does this matter, or does the script need to be somewhere else? I was thinking you might have to reference the form somewhere in the script, but I'm quite new to scripting in SharePoint so wasn't overly sure. – kloneman Nov 9 '16 at 15:09
  • Normally it's ok, the script should on the form. – Sergei Sergeev Nov 9 '16 at 15:50

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.