Question

I need to retrieve the set of fields (specifically, their internal names) that would show in the EditForm.aspx of a list, using JavaScript, preferably JSOM. In the SP.Field documentation, there is a setShowInEditForm, but no getShowInEditForm. So this is effectively a "write-only" property, which is both strange and unhelpful.

I tried using an ajax call to get the text of the EditForm.aspx and use regex to extract the internal names from the conveniently placed comments near each field, but these actually are only present in the Classic UI Experience, and the modern UI forms don't seem to have any relevant info in their source. So, that fell apart, but it was pretty hacky anyway.

So it seems there is no way to get the edit form fields with JavaScript. Please, someone, tell me I'm wrong!

Was it helpful?

Solution 2

Just a followup and basically an answer to my question, I've found that if you append ?isdlg=1 to the DefaultEditFormUrl and use that to retrieve the form with ajax, it will always be returned in the Classic UI Experience format. As I mentioned in my question, this format always seems to have those comments containing the internal names, which I can scrape with regex. Still a hacky solution since it's not official API, but it's the only solution I have found.

OTHER TIPS

Yes, there is no property like getShowInEditForm, it's only setShowInEditForm that used to control the display of a specific field in edit form by setting true to show it or false to hide it in the edit form.

But based on your requirement, I suggest doing the following:

  1. In your list, Create a new view "Edit Fields View"
  2. Add all the fields in the edit form in this view.
  3. use the below JSOM code to get the fields name of this view.

[JSOM]

function retrieveFieldsOfListView(listTitle,viewName){

   var context = new SP.ClientContext.get_current();
   var web = context.get_web();
   var list = web.get_lists().getByTitle(listTitle);
   var view = list.get_views().getByTitle(viewName);
   var viewFields = view.get_viewFields();
   context.load(viewFields);
   context.executeQueryAsync(printFieldNames,onError);


   function printFieldNames() {
      var e = viewFields.getEnumerator();
      while (e.moveNext()) {
         var fieldName = e.get_current();
         console.log(fieldName);
      }
   }

   function onError(sender,args)
   {
      console.log(args.get_message());
   }

}

I think the above workaround could match your requirement

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top