Category Archives: DFFS

DFFS Package updated to v4.4.4.24

I have fixed a few bugs and added some new functionality. You find the compete change log here, and the updated files in the download section of the user manual.

Please note that I have made a lot of small changes to this version to clean up some old code. There are always chances for errors so please test this version before applying it in a production environment.

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

Best regards,
Alexander

Limit access to a NewForm / EditForm at specific times and weekdays

I got a request for a solution to limit access to a form for 30 minutes while a report was being made to ensure no records was added or modified.

This example code must be added to the specific form – in the Custom JS section. Change the from, to and weekdays to match the time and weekdays you want to limit access.

function limitAccessToForm(arg) {
    var disableStart = new Date();
    disableStart.setHours(arg.from.hour, arg.from.minute, 0); // hour, minute, second
    var disableEnd = new Date();
    disableEnd.setHours(arg.to.hour, arg.to.minute, 0); // hour, minute, second
    var disableStartFriendly = disableStart.toLocaleString();
    var disableEndFriendly = disableEnd.toLocaleString();
    var now = new Date();
    if (now > disableStart && now < disableEnd) {
        if (arg.weekdays.length > 0) {
            var pass = false;
            var today = now.getDay();
            jQuery.each(arg.weekdays, function (i, day) {
                if (today === day) {
                    pass = true;
                    return false;
                }
            });
            if (!pass) {
                // Not today
                return;
            }
        }
        jQuery("#part1").css("visibility", "hidden");
        spjs.dffs.alert({
            "title": "No access",
            "msg": "This form is disabled between " + disableStartFriendly + " and " + disableEndFriendly,
            "ok": function () {
                if(GetUrlKeyValue("IsDlg") === "1"){
                    window.frameElement.cancelPopUp();
                }else{
                    window.history.back();
                }
            }
        });
    }
}

// If you like to limit it to specific weekdays add them to the array weekdays (sunday = 0 and saturday = 6) - leave the array empty if you want it on all weekdays
limitAccessToForm({
    "from": {
        "hour": 13,
        "minute": 0
    },
    "to": {
        "hour": 13,
        "minute": 30
    },
    "weekdays": []
});

Post any comments below, or in the forum.

Alexander

Assignments with vLookup time log: check allocated time before saving child

This example uses an Assignments list and a child list connected with vLookup to log the time used on that assignment. The code is used to ensure users doesn’t log more time than allocated to that assignment.

The example expects the vLookup connection from parent to child to pass the parent _vLookupID value to the _vLookupParentID column in the child.

The time logging in the child item must use a field named LoggedTime, and the parent list must have a field named MaxAllocatedTime that holds the max allocated time for the assignment. If this is not the case in your lists, please search and replace the field names in the code below.

Add this code to your Custom JS in your CHILD form:

function getMaxAllocatedTime() {
    var res = spjs.utility.queryItems({
        "listName": GetUrlKeyValue("parentListGuid"),
        "query": "<Where><Eq><FieldRef Name='_vLookupID' /><Value Type='Text'>" + getFieldValue("_vLookupParentID") + "</Value></Eq></Where>",
        "viewFields": ["ID", "MaxAllocatedTime"]
    });
    var num = 0;
    var max = res.items[0].MaxAllocatedTime;
    if (max.split(";#").length > 1) {
        // if MaxAllocatedTime is a calculated field the value must be split from the string 
        max = max.split(";#")[1];
    }
    if (max !== undefined) {
        num = parseInt(max, 10);
    }
    return num;
}

function getTotalLoggedTime() {
    var res = spjs.utility.queryItems({
        "listName": _spPageContextInfo.pageListId,
        "query": "<Where><Eq><FieldRef Name='_vLookupParentID' /><Value Type='Text'>" + getFieldValue("_vLookupParentID") + "</Value></Eq></Where>",
        "viewFields": ["ID", "LoggedTime"],
        "scope": "RecursiveAll"
    });
    var tot = 0;
    jQuery.each(res.items, function (i, item) {
        tot += item.LoggedTime !== null ? parseInt(item.LoggedTime, 10) : 0;
    });
    return tot;
}

function dffs_PreSaveAction() {
    var max = getMaxAllocatedTime();
    var totLogged = getTotalLoggedTime();
    var logged = getFieldValue("LoggedTime");
    if (totLogged + parseInt(logged, 10) > max) {
        spjs.dffs.alert({
            "title": "To many hours logged",
            "msg": "You have already logged " + totLogged + " hours, and with the current " + logged + " hours you exceed the max allocated time of " + max + " hours.",
            "ok": function () {
                // Close dlg
            }
        });
        // Prevent save
        return false;
    }
    // OK to save
    return true;
}

Please post any questions in the comments below.

Alexander

DFFS Package updated to v4.4.4.19

I have fixed a few remaining bugs from the version I released yesterday related to updating from an early v3.x version of DFFS with cascading dropdowns, and another for forms not using tabs. 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