Home › Forums › Classic DFFS › List all fields
- This topic has 6 replies, 3 voices, and was last updated 5 years ago by Leonid.
-
AuthorPosts
-
-
December 13, 2019 at 17:21 #28007
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? -
December 13, 2019 at 19:31 #28015
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
-
December 13, 2019 at 20:24 #28016
Any external plugin to extend its functionality?
-
December 14, 2019 at 09:15 #28020
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
-
December 16, 2019 at 17:02 #28035
-
December 16, 2019 at 19:29 #28040
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
-
December 16, 2019 at 19:47 #28042
oh my, thanks Alex!
-
-
AuthorPosts
- You must be logged in to reply to this topic.