Loading...

Follow SharePoint JavaScripts on Feedspot

Continue with Google
Continue with Facebook
or

Valid

I have finally been able to release the new version of DFFS where I have fixed several issues and done a major overhaul of the trigger handling to fix some problems with rule order when using multiple rules on the same field.

A special thanks to Rudolf Vehring for his help with testing of all the changes in this release.

You find the compete change log here, and the updated files in the download section of the user manual.

Post comments below, but use the form if you have questions or you think you have found a bug.

Best regards,
Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Here is a tool to toggle the visibility of all custom lists (BaseTemplate 100) and document libraries (BaseTemplate 101) – and also the Site Pages library (BaseTemplate 119). It is used to toggle the Hidden property on the list – which determines whether or not to show the list in Site Contents.

Please note that you must have the necessary rights (manage lists) to use it, and if you don’t you will get an error message. Also note that this snippet loads jQuery from code.jquery.com – if your site does not have Internet access you must change this script tag to refer a local copy of jQuery.

Add this snippet to a Script Editor Web Part in a Classic Web Part Page to use it.

<div >BaseUrl to the site</div>
<input type="text"  id="baseUrlInput" onkeydown="if(event.keyCode === 13){getAllLists()}"><input
    type="button" onclick="getAllLists()" value="Load all lists" />
<div id="allListsTable"></div>
<style type="text/css">
    .pageHeader {
        font-size: 1.5em;
        font-weight: 300;
    }

    .headerRow td {
        font-size: 1.5em;
        border-bottom: 1px silver solid;
    }

    .bodyRow td {
        padding: 3px 5px;
    }

    .bodyRow:hover td {
        background-color: #00ad56;
        color: #ffffff;
    }
</style>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script type="text/javascript">
    jQuery("#baseUrlInput").val(_spPageContextInfo.webServerRelativeUrl);
    function getAllLists() {
        var baseUrl = jQuery("#baseUrlInput").val();
        jQuery.ajax({
            "url": baseUrl + "/_api/web/lists?$select=Id,Title,BaseTemplate,RootFolder,Hidden&$expand=RootFolder",
            "method": "GET",
            "headers": {
                "accept": "application/json; odata=verbose",
                "content-type": "application/jsom;odata=verbose",
                "X-RequestDigest": getFormDigest()
            },
            "success": function (data) {
                var arr = [], b = [];
                jQuery.each(data.d.results, function (i, list) {
                    if (list.BaseTemplate !== 100 && list.BaseTemplate !== 101 && list.BaseTemplate !== 119) {
                        return;
                    }
                    arr.push({
                        "title": list.Title,
                        "rootfolder": list.RootFolder !== undefined ? list.RootFolder.Name : "",
                        "id": list.Id,
                        "hidden": list.Hidden
                    });
                });
                arr.sort(function (a, b) {
                    if (a.title < b.title) {
                        return -1;
                    }
                    if (a.title > b.title) {
                        return 1;
                    }
                    return 0;
                });
                b.push("<table>");
                b.push("<tr >");
                b.push("<td>");
                b.push("Title");
                b.push("</td>");
                b.push("<td>");
                b.push("URL-name");
                b.push("</td>");
                b.push("<td>");
                b.push("Hidden");
                b.push("</td>");
                b.push("</tr>");
                jQuery.each(arr, function (i, list) {
                    if (list.rootfolder === "") {
                        return;
                    }
                    b.push("<tr >");
                    b.push("<td>");
                    b.push(list.title);
                    b.push("</td>");
                    b.push("<td>");
                    b.push(list.rootfolder);
                    b.push("</td>");
                    b.push("<td>");
                    b.push("<input listguid='" + list.id + "' type='checkbox'" + (list.hidden ? " checked='checked'" : "") + " onclick='toggleVisible(this);'/>");
                    b.push("</td>");
                    b.push("</tr>");
                });
                b.push("</table>");
                jQuery("#allListsTable").html(b.join(""));
            },
            "error": function (err) {
                jQuery("#allListsTable").html(err.statusText + ": " + err.status);
            }
        });
    }

    function toggleVisible(elm) {
        var baseUrl = jQuery("#baseUrlInput").val();
        var hidden = jQuery(elm).prop("checked");
        var guid = jQuery(elm).attr("listguid");
        jQuery("#status_" + guid).remove();
        var itemPayload = {
            "__metadata": { "type": "SP.List" },
            "Hidden": hidden,
        };
        jQuery.ajax({
            "url": baseUrl + "/_api/Web/Lists/GetById('" + guid + "')",
            "type": "POST",
            "data": JSON.stringify(itemPayload),
            "headers": {
                "accept": "application/json; odata=verbose",
                "content-type": "application/jsom;odata=verbose",
                "IF-MATCH": "*",
                "X-HTTP-Method": "MERGE",
                "X-RequestDigest": getFormDigest()
            },
            success: function (data) {
                // Success
                jQuery(elm).after("<span id='status_" + guid + "' >OK</span>");
            },
            error: function (err) {
                jQuery(elm).after("<span id='status_" + guid + "' >Error! - Open the console for details (F12 > Console).</span>");
                console.log(err);
            }
        });
    }

    function getFormDigest() {
        var r = _spPageContextInfo.formDigestValue;
        if (r === undefined) {
            r = jQuery("#__REQUESTDIGEST").val();
        }
        return r;
    }
</script> 

Hope you find this tool useful.

Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

On July 1, 2019 I will increase the price on the Site license for Dynamic Forms for SharePoint (DFFS), SPJS Charts for SharePoint (Charts) and CommentBox for SharePoint (cBox).

This is the changes:

DFFS: From $50 to $100.
Charts: From $50 to $75.
cBox: From $50 to $75.

The price for a Site Collection license will not change this time.

Best regards,
Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

One of the main areas of confusion when using DFFS is the automatic rule reversing of rules that are NOT evaluated to true.

This example show how most users first set it up and ends up with the wrong result. I’ll first show how it is set up to make it fail, and then I’ll highlight the missing part at the bottom of this post.

The example form

Let’s say you have a choice field TabVisibility that controls the visibility of a specific tab. For this example I have created a choice field with two values: Show and Hide, an have set up three rules.

The tabs:

Tab is set to hidden but this will not work because the rules show below will override it.

The rules:

One for hiding the tab when the TabVisibility choice field is empty:

One for showing the tab when the value is Show:

And one for when the value is Hide:

This is how it looks when loading NewForm and the value in TabVisibility = blank, but it is not doing what you expect:

This must be wrong – the tab is not hidden??? Why this is not working

When you have trouble with a form you should always use the Debug this rule setting:

This will show you the debug panel below the form:

When the form loads, each of the three rules are evaluated. The first rule is evaluated as “true” and hides the tab as it should:

Hides the tab.

Then the next rule runs and is evaluated as “false” and does the opposite of what it is configured to do. It doesn’t do anything wrong here because the tab is already hidden, but you see where this is going:

Should show the tab if true, but reverses and hides the tab instead.

Then the last rule comes in and messes it up by showing the tab despite it being set up to HIDE the tab and not to show it:

Shows the tab because the rule is reversed when not evaluated to true. Why is this happening?

The reason for this behavior is to avoid writing two rules for every action and just let DFFS handle the reversing – for example if a Yes/No field is checked: show some fields, set some fields required etc. Then if the field is unchecked, all visible field are hidden, required fields are set as optional etc. This is by design to limit the number of rules required to make a dynamic form.

This will however create problems when you use multiple rules on for example a single choice column as described above.

How to fix it

In this scenario you must use the No reversing of this rule setting in each of the three rules (optionally you can check the Disable reversing of all rules in the top of the Rules tab):

No reversing set on each rule.

When you have done this your NewForm will load correctly and hide the tab:

That’s it – post any comments below, or use the forum.

Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The code snippet linked below is used to dump all the list fields to a file to enable me to recreate the list when investigating a possible bug in DFFS.

How to use the snippet

Go to the DFFS enabled list you want to copy, and change the URL from …/Lists/ExampleListName/ExampleViewName.aspx to …/Lists/
ExampleListName /NewForm.aspx.

Hit F12 to bring up the developer console and paste the code directly in the console and hit Enter.

This will download the field definition as a file that you can email to me or attach in a forum post.

The file only contains the name and description of the fields, and choices in a choice field so there should not be any compromising information in the file.

Get the code snippet

Get the file her

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have fixed a few small bugs – you find the change log here, and the updated files in the download section of the user manual.

PS: The date on the zip file is 2019-03-31 – I just didn’t find time to publish it until now.

Post comments below, but use the form if you have questions or you think you have found a bug.

Best regards,
Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have fixed a bug with using multiple rules triggering on change / change from initial value on a multichoice field resulting in only the last rule on this trigger to actually run.

You find the change log here, and the updated files in the download section of the user manual.

Post comments below, but use the form if you have questions or you think you have found a bug.

Best regards,
Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have released a new version of the DFFS package (v4.4.3.63) that replaces v4.4.3.62 that I released yesterday.

I was made aware of a major regression bug that I accidentally introduced while fixing and issue with using multiple rules triggering on change of the same field.

I have pulled the previous version and updated the change log here.

You find the updated files in the download section of the user manual.

Post comments below, but use the form if you have questions or you think you have found a bug.

Best regards,
Alexander


  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I have released a new version of the DFFS package (v4.4.3.62) with a few bugfixes.

You find the change log here and the files in the download section of the user manual.

Post comments below, but use the form if you have questions or you think you have found a bug.

Best regards,
Alexander

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

This example show how you can use a set of rules to ensure only persons assigned in a people picker in the form, or members in an admin group can view or edit a list item.

Add these three rules:

This rule doesn’t have any actions. This rule doesn’t have any actions. This rule checks the two previous rules, and calls a function if both are false.

Then add this function to your Custom JS:

function noAccessToThisForm(){
jQuery("#part1").hide();
spjs.dffs.alert({
"title":"No access",
"msg":"You don't have access to this list item.",
"ok":function(){
window.history.back();
}
});
}

You can use this setup in both DispForm and EditForm, and it will show this message box if the user doesn’t have access:

Post any questions below, or use the forum.

Alexander

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview