This project has moved. For the latest updates, please go here.

Office 365 custom list only firing in when form in edit mode

Jun 19, 2014 at 8:33 PM
Edited Jun 19, 2014 at 8:35 PM
Hi,

I have a custom list in office 365. I have saved my "helloworld.html" file in the site assets folder along with the two .min files (jquery and the sputility.)

I have my CEWP on the Default Edit form. I'm trying to make a field read only and place 'Hello world' in the Title field. Opening the default edit form, the Title field remains at test and nothing is set to read only.

Now edit the Default Edit form and edit the CEWP. You don't even have to change anything (URL of HTML file is already set, simply click "Apply" and everything works. Hello world, fields go to read only.

Now click "Stop Editing" and the page returns to normal, but no script is firing. Is this an issue with O365 SP online? Anyone else seeing this?

Thanks
Coordinator
Jun 22, 2014 at 7:03 PM
Hey,
Sorry you are having trouble getting it working. If I understand correctly, you're trying to do something like this:
<script src="/kitsite/Files/jquery-1.11.0.min.js"></script>
<script src="/kitsite/Files/sputility.min.js"></script>
<script>
// wait for the window to load
$(window).load(function () {
   // EXAMPLE: Set the value of the Title field to Hello world!
   SPUtility.GetSPField('Title').SetValue('Hello world!');
   SPUtility.GetSPField('Project ID').MakeReadOnly();
});
</script>
I set it up like you said above and couldn't see a problem. Are you getting any javascript errors on the page? Does everyone have permissions to the js and html files? Also, I can glance at your code if you'd like to post it.
Thanks,
Kit
Jun 23, 2014 at 1:52 PM
Edited Jun 23, 2014 at 1:54 PM
Hi,
<script src="/testsite/SiteAssets/jquery-1.11.1.min.js"></script>
<script src="/testsite/SiteAssets/sputility.min.js"></script>
<script>
// wait for the window to load
$(window).load(function () {
// EXAMPLE: Set the value of the Title field to Test Test Test!
SPUtility.GetSPField('Title').SetValue('Test Test Test').MakeReadOnly();
SPUtility.GetSPField('Col1').MakeReadOnly();
});
</script>
What has me concerned and considering this to be an environment problem, is that I don’t get any script error… am a full site admin… and everything works fine after I edit and “apply” changes to the page.
Thanks
Coordinator
Jun 23, 2014 at 11:23 PM
That is very strange... your code above looks OK to me. Another thing to try is to copy your code above (the contents of helloworld.html essentially) and put that in a Script Editor web part directly. That might narrow down if it is a problem with the scripts or the CEWP.
Jun 24, 2014 at 4:18 PM
Good idea. I tried that, but in that case nothing fires whatsoever. I stumped.
Jun 26, 2014 at 3:37 AM
As I expected... I moved this from O365 to an OnPrem instance... no issues... strange, but if other encounter it I wanted to post this.
Marked as answer by korbbot on 6/25/2014 at 8:37 PM
Sep 24, 2014 at 6:15 PM
I am having the exact same issue. All works fine when I hit apply but when I stop editing the form the fields go right back to editable and visible. I am stumped. Did this ever get resolved?
Coordinator
Sep 25, 2014 at 3:12 AM
keefahholt,
I haven't been able to reproduce this in my Office 365 environment so I'm not sure what the issue is. I also run my SharePoint 2013 integration tests in an O365 environment which makes this issue seem really weird to me. I've had success with both the Content Editor and the Script Editor web parts.

To be clear, you followed the steps on the Installation page? Can you try clicking "OK" instead of "Apply" when editing the CEWP? If you edit the CEWP again do you see your HTML page in the options? Any other little details like this might indicate what the problem is.
Thanks,
Kit
Dec 11, 2014 at 9:40 AM
Hello from Italy.
Same problem here (Office 365 plan P1):
  • a document library, named Javascript, containing copies of jquery-1.11.1.min.js, last sputility.min.js, and my sample html page destinazione.html
  • a list named Origine, with hers fields Title and Valore (both are single lines of text)
  • another list named Destinazione, with field Title (single line of text), Valore (lookup to Origine.Valore) and Copia (single line of text)
    I've added the web part to "default edit page" as described on "installation" page, "content link" is set to /Javascript/destinazione.html
    And it works (when I click on Apply, the "title" field changes to Hello World) ... when editing. After clicking "stop editing"... goodbye, modifications.
This is destinazione.html's content
<script src="/Javascript/jquery-1.11.1.min.js"></script>
<script src="/Javascript/sputility.min.js"></script>
<p>a</p>
<script>
// wait for the window to load
$(window).load(function () {
   // EXAMPLE: Set the value of the Title field to Hello world!
   SPUtility.GetSPField('Title').SetValue('Hello world!');
});
</script>
The differences between your sample and my sample are:
  • reference to jquery-1.11.0.min instead 1.11.1.min (I noticed that korbbot too linked to 1.11.1 version)
  • adding of an html paragraph to be sure that destinazione.html gets loaded
My "real" goal is this: whenever the user modifies his choice on the lookup field, the chosen value should be copied to the "Copia" field.
I need this to customize an Event list, in order to maintain "syncability" to Outlook 2013 desktop while adding useful informations obtained via lookup fields.
No, I cannot edit the "Location" field in order to change it from "single line of text" to "lookup to Locations list" if I need to sync this list to Outlook.

Hope that helps
Dec 11, 2014 at 10:23 AM
Edited Dec 11, 2014 at 10:24 AM
Problem seems to be solved now (just click to OK when editing webpart instead of Apply).

Now, however, I'm stuck with my "real" goal: I need to copy value of the lookup ("Valore") field into "Copia" field (this should be done for every "new" item and every "edit" operation on existing items).

I tried
<script src="/Javascript/jquery-1.11.1.min.js"></script>
<script src="/Javascript/sputility.min.js"></script>
<script>
// wait for the window to load
// $(window).load(function () {
// wait for the form to be submitted
$(form).submit(function () {
   var invalue = SPUtility.GetSPField('Valore').GetValue();
   SPUtility.GetSPField('Copia').SetValue(invalue);
});
</script>
But, analyzing the HTML source of the Edit page, it seems that form "submit" event is already bound to a function.
<form method="post" action="EditForm.aspx?ID=1&amp;Source=https%3a%2f%2fMYSITE.sharepoint.com%2fLists%2fDestinazione%2fAllItems.aspx&amp;ContentTypeId=0x0100363BE8913E2F4B42923E7AF231E305EE" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" enctype="multipart/form-data">
What now? :-(
May I bind my function to the "change" event of the "aspnetForm"?
Coordinator
Dec 11, 2014 at 2:19 PM
So you were able to get it working just by clicking OK instead of APPLY? Interesting...

For your other problem, instead of listening to the form submit function, just put your code in a PreSaveAction function:
<script src="/Javascript/jquery-1.11.1.min.js"></script>
<script src="/Javascript/sputility.min.js"></script>
<script>

function PreSaveAction() {   
   var invalue = SPUtility.GetSPField('Valore').GetValue();
   SPUtility.GetSPField('Copia').SetValue(invalue);
   // always proceed with save
   return true;
}
</script>
This function is automatically called by SharePoint when the user clicks the save button!
Marked as answer by KitMenke on 12/15/2014 at 8:36 AM
Dec 11, 2014 at 2:51 PM
Edited Dec 11, 2014 at 3:40 PM
Kit. You've just been elected to MyPersonalSavior role. Many... many thanks.
Additionally, how can I mark your last post as an answer?
Dec 15, 2014 at 8:49 AM
Edited Dec 15, 2014 at 9:27 AM
Argh. Italian field names (with accents) are screwing up the webpart, it seems.
I confirm that using SPUtility.GetSPFieldByInternalName bypasses this issue.
I need to further inquire on this, however, because the "Cliente" custom type was originally derived from the "Contact" type (I've setted the language in english to find options, menu items and so on more easily).
This code works
function PreSaveAction() {   
   var cognome = SPUtility.GetSPField('Cognome').GetValue();
   var nome = SPUtility.GetSPField('Nome').GetValue();
   var nomecompleto = nome + " " + cognome;
   // setta Full name
   SPUtility.GetSPField('Nome e cognome').SetValue(nomecompleto);
//   var azienda = SPUtility.GetSPField('Società').GetValue(); <--- Società has accented letters but now it's commented out
   // setta denominazione-ragione sociale a seconda se e' valorizzato il campo Company
//   if (azienda != "" ) {
//  SPUtility.GetSPField('Denominazione').SetValue(azienda);
//  }
//  else {
//  SPUtility.GetSPField('Denominazione').SetValue(nomecompleto);
//  }
   // continua col salvataggio
   return true;
}
While this stopped "Save" functionality.
function PreSaveAction() {   
   var cognome = SPUtility.GetSPField('Cognome').GetValue();
   var nome = SPUtility.GetSPField('Nome').GetValue();
   var nomecompleto = nome + " " + cognome;
   // setta Full name
   SPUtility.GetSPField('Nome e cognome').SetValue(nomecompleto);
 var azienda = SPUtility.GetSPField('Società').GetValue(); <--- Società has accented letters 
   // setta denominazione-ragione sociale a seconda se e' valorizzato il campo Company
//   if (azienda != "" ) {
//  SPUtility.GetSPField('Denominazione').SetValue(azienda);
//  }
//  else {
//  SPUtility.GetSPField('Denominazione').SetValue(nomecompleto);
//  }
   // continua col salvataggio
   return true;
}
Coordinator
Dec 15, 2014 at 2:50 PM
I tested created a text field named "Società" and I was able to call GetSPField. Could you put your code in a try/catch to print out what error you're getting?
function PreSaveAction() {
    try {
        var cognome = SPUtility.GetSPField('Cognome').GetValue();
        var nome = SPUtility.GetSPField('Nome').GetValue();
        var nomecompleto = nome + " " + cognome;
        
        // setta Full name
        SPUtility.GetSPField('Nome e cognome').SetValue(nomecompleto);
        var azienda = SPUtility.GetSPField('Società').GetValue();
        
        // setta denominazione-ragione sociale a seconda se e' valorizzato il campo Company
        if (azienda !== "" ) {
            SPUtility.GetSPField('Denominazione').SetValue(azienda);
        } else {
            SPUtility.GetSPField('Denominazione').SetValue(nomecompleto);
        }
        // continua col salvataggio
    } catch(e) {
        alert(e);
    }
    return true;
}
Dec 15, 2014 at 3:14 PM
The error message states "Unable to get an SPField named SocietA" (the last A is a capital A with a ~ on top, I never saw this letter on my entire life).
It seems like a cut&paste problem here, I've copied field name from the content type definition into Javascript code because my actual keyboard (English US) has no accented letters.
I'll try starting from scratch (with an Italian keyboard layout) creating the custom content type entirely in Italian language, but I'm confident this will solve my issue.
Best regards again