Alexander Bautz

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 4,087 total)
  • Author
    Posts
  • in reply to: ShowMenuForm? #35319
    Alexander Bautz
    Keymaster

    You can change this:

    var rh = jQspjs("#s4-ribbonrow").height();

    to this:

    var rh = 126; // Adjust if this is not the actual height of your banner

    and see if that keeps the height of the form consistent.

    Alexander

    in reply to: ShowMenuForm? #35304
    Alexander Bautz
    Keymaster

    This function is only used internally to hide the ribbon so I didn’t add any function to toggle it visible again, but you can use something like this:

    spjs.dffs.showFormMenu = function() {
        var rh = jQspjs("#s4-ribbonrow").height();
        var wh = jQspjs("#s4-workspace").height();
        jQspjs("#s4-ribbonrow").show();
        jQspjs("#s4-workspace").css("height", (wh - rh) + "px");
    }

    Alexander

    in reply to: ShowMenuForm? #35298
    Alexander Bautz
    Keymaster

    I’m not sure what function you are referring to (I cannot find this function in spjs.utility) – what kind of functionality are you looking for?

    Alexander

    Alexander Bautz
    Keymaster

    Hi,
    You can use a script like this example. You must run it in the console of one of your forms in each subsite as it uses some code from DFFS.

    Code example:

    var allConfig = spjs.utility.queryItems({
        "listName": "SPJS-DynamicFormsForSharePoint",
        "query": "<Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where>",
        "viewFields": ["ID", "Title", "blob"]
    });
    jQuery.each(allConfig.items, function (i, item) {
        if (item.Title.charAt(0) === "/" && item.blob !== null && item.blob.charAt(0) === "{") {
            var config = JSON.parse(item.blob);
            // Use console.log to view the config in the console to locate the parameters you want to change
            // console.log(config);
            // This example changes redirEditToDisp to false
            if (config.redir.redirEditToDisp) {
                config.redir.redirEditToDisp = false;
                // Backup current config
                var backupRes = spjs.utility.addItem({
                    "listName": "SPJS-DynamicFormsForSharePoint",
                    "data": { "Title": "[backup]" + item.Title, "blob": item.blob }
                });
                if (backupRes.success) {
                    // Apply changes if config was backed up successfully
                    var updateRes = spjs.utility.updateItem({
                        "listName": "SPJS-DynamicFormsForSharePoint",
                        "id": item.ID,
                        "data": { "blob": JSON.stringify(config) }
                    });
                    if (updateRes.success) {
                        console.log("Made backup and updated config for " + item.Title);
                    }
                } else {
                    console.log("*** Failed to backup config for " + item.Title + ": " + backupRes.errorText + ". No changes were made to the config.");
                }
            }
        }
    });

    This script will loop trough ALL configs in the current site and make changes. It will make a backup of the original config in case you need to roll back. If so, open the “Export, import and restore” tab and hit “Browse restore points and deleted configurations”.

    Please read the comments in the code and make changes to match the changes you want to make.

    Alexander

    in reply to: List item record lock #35281
    Alexander Bautz
    Keymaster

    You can use the Check out list items functionality in the Misc tab in EditForm.

    Alexander

    in reply to: Query/Update/Delete an item in JavaScript #35269
    Alexander Bautz
    Keymaster

    No, this is not documented in any of the user manuals. What kind of information are you looking for?

    Alexander

    in reply to: Query/Update/Delete an item in JavaScript #35265
    Alexander Bautz
    Keymaster

    Thanks the for donation!

    PS: I edited the REST examples and changed from getbytitle to getbyid.

    Alexander

    in reply to: Query/Update/Delete an item in JavaScript #35260
    Alexander Bautz
    Keymaster

    Built in to DFFS you find function for crud (Create, Read, Update, and Delete) in the spjs.utility library like this.

    Create a list item:

    spjs.utility.addItem({
        "listName": "DFFS_TestList", // List display name or GUID
        "listBaseUrl": _spPageContextInfo.webServerRelativeUrl,
        "data": {"Title": "New item"}
    });

    Read items:

    spjs.utility.queryItems({
        "listName": "DFFS_TestList", // List display name or GUID
        "listBaseUrl": _spPageContextInfo.webServerRelativeUrl,
        "query": "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>New item</Value></Eq></Where>",
        "viewFields": ["ID", "Title"]
    });

    Update list item with id 150:

    spjs.utility.updateItem({
        "listName": "DFFS_TestList", // List display name or GUID
        "listBaseUrl": _spPageContextInfo.webServerRelativeUrl,
        "id": 150,
        "data": {"Title": "New item - updated"}
    });

    Delete item with i 150:

    spjs.utility.deleteItem({
        "listName": "DFFS_TestList", // List display name or GUID
        "listBaseUrl": _spPageContextInfo.webServerRelativeUrl,
        "id": 150
    });

    PS: Please note that the built in methods use the old webservice methods to keep compatibility with SP 2007 and SP 2010. I recommend using the REST API to do these kind of operations if you are writing your own custom js.

    Create list item with REST:

    spjs.utility.getListByUrlName(_spPageContextInfo.webServerRelativeUrl, "DFFS_TestList").done(function (list) {
        var item = {
            "__metadata": { "type": list.type },
            "Title": "New item created with REST"
        };
        jQuery.ajax({
            "url": _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbyid('"+list.id+"')/items",
            "method": "POST",
            "data": JSON.stringify(item),
            "headers": {
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
            },
            "success": function (data) {
                complete(data);
            },
            "error": function (data) {
                console.log(data);
            }
        });
    });

    Read list items with REST:

    spjs.utility.getListByUrlName(_spPageContextInfo.webServerRelativeUrl, "DFFS_TestList").done(function (list) {
        jQuery.ajax({
            "url": _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbyid('"+list.id+"')/items?$filter=Title eq 'New item created with REST'",
            "method": "GET",
            "headers": {
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose"
            },
            "success": function (data) {
                console.log(data);
            },
            "error": function (data) {
                console.log(data);
            }
        });
    });

    Update list item id 152 with REST:

    spjs.utility.getListByUrlName(_spPageContextInfo.webServerRelativeUrl, "DFFS_TestList").done(function (list) {
        var item = {
            "__metadata": { "type": list.type },
            "Title": "New item created with REST - updated"
        };
        jQuery.ajax({
            "url": _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbyid('"+list.id+"')/items(152)",
            "method": "PATCH",
            "data": JSON.stringify(item),
            "headers": {
                "Accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "If-Match": "*",
                "X-HTTP-Method": "MERGE",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
            },
            "success": function (data) {
                console.log(data);
            },
            "error": function (data) {
                console.log(data);
            }
        });
    });

    Send item with id 152 to the recycle bin with REST:

    spjs.utility.getListByUrlName(_spPageContextInfo.webServerRelativeUrl, "DFFS_TestList").done(function (list) {
        jQuery.ajax({
            "url": _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbyid('"+list.id+"')/items(152)/recycle",
            "method": "PATCH",
            "headers": {
                "Accept": "application/json;odata=verbose",
                "X-HTTP-Method": "DELETE",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
            },
            "success": function (data) {
                console.log(data);
            },
            "error": function (data) {
                console.log(data);
            }
        });
    });

    Read more here: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

    Alexander

    • This reply was modified 1 week, 3 days ago by Alexander Bautz. Reason: Replaced getbytitle with getbyid in the REST examples
    in reply to: Make a "Copy" button #35258
    Alexander Bautz
    Keymaster

    Hi,
    You can do it in dffs_ready if you wrap it up something like this inside the function:

    if(GetUrlKeyValue("CreateCopy") === "1"){
        var str = sessionStorage.getItem("SaveAndCreateNewData"), data;
        if(str !== null){
            data = JSON.parse(str);
            jQuery.each(data,function(fin,val){
                 setFieldValue(fin,val);
             });
        }
    }
    spjs.ac.textfield(...);

    Alexander

    in reply to: Make a "Copy" button #35246
    Alexander Bautz
    Keymaster

    Hi,
    Before you apply the function spjs.ac.textField(…) you cannot use the spjs.ac.setFieldValue function – use the regular setFieldValue(fin, val) function instead.

    Alexander

    in reply to: Make a "Copy" button #35244
    Alexander Bautz
    Keymaster
    in reply to: Different form for different view. #35233
    Alexander Bautz
    Keymaster

    Add these two functions to your Custom JS:

    function getIsFromView1(){
        var sourceView = document.referrer.split("/").pop();
        if(sourceView.indexOf("View1.aspx") === 0){
            return true;
        }
        return false;
    }
    
    function getIsFromView2(){
        var sourceView = document.referrer.split("/").pop();
        if(sourceView.indexOf("View2.aspx") === 0){
            return true;
        }
        return false;
    }

    Now set up two rules using the trigger “Custom JavaScript function” where you add getIsFromView1 to the “This value” field in the first rule and getIsFromView2 in the same field in the second rule.

    In the “Visible tabs” you put the name of the tab to show and in the “Hidden tabs” you add *.

    Let me know how this works out.

    Alexander

    Alexander Bautz
    Keymaster

    There is no easy way to bulk edit items, but it can be done with a custom script that loops through all stored configurations.

    How many configs do you need to change?

    Alexander

    Alexander Bautz
    Keymaster

    By default SharePoint redirects you back to wherever the “Source” parameter in the URL query string points to.

    If you open a DispForm and then navigates to EditForm the default redirect would be back to the view you came from – are you using any custom js or misc tab settings to change the redirect?

    Alexander

    in reply to: Make a "Copy" button #35217
    Alexander Bautz
    Keymaster

    If you use an AC field you must not invoke the AC function on the field until you are done prefilling the fields from the localStorage object.

    Alexander

Viewing 15 posts - 1 through 15 (of 4,087 total)