List all fields

Forums Dynamic Forms for SharePoint List all fields

Viewing 6 reply threads
  • Author
    Posts
    • #28007
      Leonid
      Participant

      Im missing something. I need to get an array of all form fields (internal names) based on the name criteria. E.g. all fields with internal name containing “_Score”. Treid to use

      spjs.dffs.fields

      and it didnt work.
      Any suggestions?

    • #28015
      Alexander Bautz
      Keymaster

      You find a list of all fields (and you can download it as a .csv file) from the Fields tab in the configuration of a DFFS form.

      Alexander

    • #28016
      Filipe Ribeiro
      Participant

      Any external plugin to extend its functionality?

    • #28020
      Alexander Bautz
      Keymaster

      Not sure exactly what you are looking for – is it a method of listing all fields for use in Custom JS in a DFFS form, or in a standalone solution?

      Alexander

    • #28035
      Leonid
      Participant

      Yes, I need a method/property to use in Custom JS javascript. Preferably it will be array, list or collection of fileds that I can filter by InternalName

      • This reply was modified 3 months, 3 weeks ago by Leonid.
    • #28040
      Alexander Bautz
      Keymaster

      You can use something like this:

      function getListFields(baseUrl, listUrlName) {
          var endpoint = baseUrl + "/_api/Web/Lists?$filter=RootFolder/Name eq '" + listUrlName + "'&$expand=Fields", d = jQuery.Deferred();
          jQspjs.ajax({
              "url": endpoint,
              "method": "GET",
              "headers": {
                  "accept": "application/json; odata=verbose",
                  "content-type": "application/json;odata=verbose",
                  "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
              },
              "success": function (b) {
                  if (b.d.results.length > 0) {
                      var c = b.d.results[0], url, fields = {};
                      jQspjs.each(c.Fields.results, function (i, a) {
                          fields[a.InternalName] = {
                              "fin": a.InternalName,
                              "disp": a.Title,
                              "type": a.TypeAsString
                          };
                          if (a.TypeAsString === "Choice" || a.TypeAsString === "MultiChoice") {
                              fields[a.InternalName].choices = a.Choices.results;
                          }
                      });
                      d.resolve({
                          "success": true,
                          "fields": fields
                      });
                  } else {
                      d.resolve({
                          "success": false,
                          "message": "No list with the URL name '" + listUrlName + "' was found on '" + baseUrl + "'"
                      });
                  }
              },
              "error": function (a) {
                  d.resolve({
                      "success": false,
                      "message": "No list with the URL name '" + listUrlName + "' was found on '" + baseUrl + "'"
                  });
              }
          });
          return d.promise();
      }

      Call it like this:

      getListFields("/Sites/YourSite", "Your_list_URL_name").done(function (o) {
          if (o.success) {
              console.log(o.fields);
          } else {
              console.log(o.message);
          }
      });

      This returns the list of fields as an object you can access like this:

      o.fields.YourFieldInternalName

      If you prefer an array you can change the code to push it into an array instead of construction the object.

      Alexander

    • #28042
      Leonid
      Participant

      oh my, thanks Alex!

Viewing 6 reply threads
  • You must be logged in to reply to this topic.