v4.4.5.55 has been released

Home Forums Classic DFFS v4.4.5.55 has been released

Tagged: 

Viewing 19 reply threads
  • Author
    Posts
    • #38545
      Alexander Bautz
      Keymaster

        I have published v4.4.5.55 of the Classic DFFS to fix a problem where the label of the attachment field was hidden when the field was set as readonly.

        Alexander

      • #38551
        Wendi Watson
        Participant

          Hello Alexander

          I am hoping you can help me here. I am trying to launch a Custom JS script but it is not working. When I view the console here is the message I see
          VM153:9 Uncaught ReferenceError: setFieldDisabled is not defined
          at toggleFieldToDisable (<anonymous>:9:9)
          at <anonymous>:14:1
          at b (jQuery.js?v=1744295668044:2:866)
          at He (jQuery.js?v=1744295668044:2:48648)
          at E.fn.init.append (jQuery.js?v=1744295668044:2:49999)
          at Object.loadCustomJS (eval at <anonymous> (DFFS_frontend_min.js:10:1), <anonymous>:1:202332)
          at Object.loadDependencies (eval at <anonymous> (DFFS_frontend_min.js:10:1), <anonymous>:1:204183)
          at HTMLDocument.eval (eval at <anonymous> (DFFS_frontend_min.js:10:1), <anonymous>:1:176726)
          at e (jQuery.js?v=1744295668044:2:30310)
          at t (jQuery.js?v=1744295668044:2:30612)

          and here is the JS I am trying to use

          function toggleFieldToDisable() {
          var f1 = getFieldValue(“Control_x0020_Certified_x003f_”);
          var f2 = getFieldValue(“Checklist_x0020_Certified_x003f_”);
          var f3 = getFieldValue(“Checker_x0020_Inventory_x0020_Ce”);

          if (f1 === “Yes” && f2 === “Yes” && f3 === “Yes”) {
          setFieldDisabled(“Requesting_x0020_an_x0020_Except”, true);
          } else {
          setFieldDisabled(“Requesting_x0020_an_x0020_Except”, false);
          }
          }

          // Call it immediately on form load
          toggleFieldToDisable();

          // Set up watchers so it also runs when these fields change
          spjs.dffs.doReadOnlyOnChange.push({fin:”Control_x0020_Certified_x003f_”, functionName:toggleFieldToDisable});
          spjs.dffs.doReadOnlyOnChange.push({fin:”Checklist_x0020_Certified_x003f_”, functionName:toggleFieldToDisable});
          spjs.dffs.doReadOnlyOnChange.push({fin:”Checker_x0020_Inventory_x0020_Ce”, functionName:toggleFieldToDisable});

          setFieldDisabled(“Requesting_x0020_an_x0020_Except”, true);

          I am not able to understand where I need to change the file location for JS and wondering if you can help me?

        • #38552
          Wendi Watson
          Participant

            Here is a screenshot of the error

            Attachments:
          • #38556
            Alexander Bautz
            Keymaster

              Hi,
              This error states that you are missing a function named setFieldDisabled. If you have copied this custom js code from another site you must ensure you include this function also.

              Alexander

            • #38558
              Wendi Watson
              Participant

                Thank you, I have to admit I am not very up on this. How do I get that funtion to include and where do I add it?

              • #38559
                Wendi Watson
                Participant

                  I have added the function to the Custom JS tab in DFFS and then I call it with a rule. Am I missing where else to add it?

                • #38560
                  Alexander Bautz
                  Keymaster

                    Where did you get the rest of the code from? – I’m guessing the code has been copied from somewhere, but you forgot to include this one function.

                    Without knowing exactly what you want to do with the rest of the code I’m not sure if just writing a code example will work for you, but from the function name I’m guessing it could be done something like this:

                    function setFieldDisabled(fin, disabled){
                        if(disabled){
                            spjs.dffs.doReadOnly([fin]);
                        }else{
                            spjs.dffs.undoReadOnly([fin]);
                        }
                    }
                    

                    Alexander

                  • #38561
                    Wendi Watson
                    Participant

                      Chat GPT gave me the code.

                    • #38562
                      Wendi Watson
                      Participant

                        Do I add this piece of code that you gave at the end of the other code?

                      • #38563
                        Wendi Watson
                        Participant

                          What I am trying to do is if all 3 fields are yes, then a 4th field is disabled but if ANY of those 3 fields is no then that field is NOT disabled

                        • #38564
                          Alexander Bautz
                          Keymaster

                            I see. Chat GPT have not given you code that will work when you toggle the fields – only when the form loads (if you add the missing function).

                            What kind of fields are f1, f2 and f3 – Yes/No fields, or choice fields where one of the options are Yes?

                            Alexander

                          • #38565
                            Wendi Watson
                            Participant

                              The fields are choice fields.

                            • #38566
                              Alexander Bautz
                              Keymaster

                                What kind of choice field – radiobutton, dropdown or multiselect?

                                Alexander

                              • #38567
                                Alexander Bautz
                                Keymaster

                                  This example should work for radiobutton fields:

                                  const arrOfChoiceFields = ["Control_x0020_Certified_x003f_", "Checklist_x0020_Certified_x003f_", "Checker_x0020_Inventory_x0020_Ce"];
                                  
                                  // Trigger on change
                                  arrOfChoiceFields.forEach(fin => {
                                      jQuery("#dffs_" + fin).find("input:radio").on("click", function(){
                                          toggleFieldToDisable();
                                      });
                                  });
                                  
                                  function setFieldDisabled(fin, disabled){
                                      if(disabled){
                                          spjs.dffs.doReadOnly([fin]);
                                      }else{
                                          spjs.dffs.undoReadOnly([fin]);
                                      }
                                  }
                                  
                                  function toggleFieldToDisable(){
                                      let allYes = true;
                                      arrOfChoiceFields.forEach(fin => {
                                          if(getFieldValue(fin) !== "Yes"){
                                              allYes = false;
                                          }
                                      });
                                      setFieldDisabled("Requesting_x0020_an_x0020_Except",allYes);
                                  }
                                  
                                  // Trigger on page load
                                  toggleFieldToDisable();
                                  

                                  Please verify that I have the correct internal names for your fields.

                                  Alexander

                                • #38568
                                  Wendi Watson
                                  Participant

                                    Thank you Alexander, how would I modify this to work with Choice Yes or no fields?

                                  • #38569
                                    Alexander Bautz
                                    Keymaster

                                      I need to know what you mean – is it a “Choice (menu to choose from) or a “Yes/No (check box) type field?

                                      If it is the first, which subtype of field:

                                      • Drop-Down Menu
                                      • Radio Buttons
                                      • Checkboxes (allow multiple selections)

                                      Alexander

                                    • #38572
                                      Wendi Watson
                                      Participant

                                        Hi Alexander,

                                        They are dropdown. I am also getting another error on another piece of code. It seems like i don’t have the spjs.dffs? I am confused because some JS works and others don’t,

                                        I am using this version DFFS_v4.4.5.55_2025-04-07.

                                        This is the code. I am trying to just hide a tab based on a list that has a Person field and a Role field. I want to hide the tab based on the persons role. I attached the error as well. I feel like my problem is I am missing a file or something? Is there anyway I can get around this?

                                        function checkUserRoleAndToggleTab() {
                                        var currentUser = _spPageContextInfo.userLoginName;

                                        // Query the Roles list for current user
                                        spjs.dffs.getListItems({
                                        listName: “Roles”,
                                        query: “<Where><Eq><FieldRef Name=’Person’ LookupId=’TRUE’ /><Value Type=’Integer’>” + _spPageContextInfo.userId + “</Value></Eq></Where>”,
                                        viewFields: [“Role”],
                                        onComplete: function (data) {
                                        var hideTab = false;

                                        if (data.count > 0) {
                                        var role = data.items[0].Role;

                                        // Check if role is “Owner”
                                        if (role && role.trim().toLowerCase() === “owner”) {
                                        hideTab = true;
                                        }
                                        }

                                        if (hideTab) {
                                        spjs.dffs.hideTab(“test”);
                                        } else {
                                        spjs.dffs.showTab(“test”);
                                        }
                                        }
                                        });
                                        }

                                        // Run the function
                                        checkUserRoleAndToggleTab();

                                        Attachments:
                                      • #38574
                                        Wendi Watson
                                        Participant

                                          Hi Alexander,

                                          They are dropdown. I am also getting another error on another piece of code. It seems like i don’t have the spjs.dffs? I am confused because some JS works and others don’t,

                                          I am using this version DFFS_v4.4.5.55_2025-04-07.

                                          This is the code. I am trying to just hide a tab based on a list that has a Person field and a Role field. I want to hide the tab based on the persons role. I attached the error as well. I feel like my problem is I am missing a file or something? Is there anyway I can get around this?

                                          function checkUserRoleAndToggleTab() {
                                          var currentUser = _spPageContextInfo.userLoginName;

                                          // Query the Roles list for current user
                                          spjs.dffs.getListItems({
                                          listName: “Roles”,
                                          query: “<Where><Eq><FieldRef Name=’Person’ LookupId=’TRUE’ /><Value Type=’Integer’>” + _spPageContextInfo.userId + “</Value></Eq></Where>”,
                                          viewFields: [“Role”],
                                          onComplete: function (data) {
                                          var hideTab = false;

                                          if (data.count > 0) {
                                          var role = data.items[0].Role;

                                          // Check if role is “Owner”
                                          if (role && role.trim().toLowerCase() === “owner”) {
                                          hideTab = true;
                                          }
                                          }

                                          if (hideTab) {
                                          spjs.dffs.hideTab(“test”);
                                          } else {
                                          spjs.dffs.showTab(“test”);
                                          }
                                          }
                                          });
                                          }

                                          // Run the function
                                          checkUserRoleAndToggleTab();

                                        • #38587
                                          Alexander Bautz
                                          Keymaster

                                            To your original question – here is how you can change it to work with dropdown fields:

                                            const arrOfChoiceFields = ["Control_x0020_Certified_x003f_", "Checklist_x0020_Certified_x003f_", "Checker_x0020_Inventory_x0020_Ce"];
                                            
                                            // Trigger on change
                                            arrOfChoiceFields.forEach(fin => {
                                                jQuery("#dffs_" + fin).find("select").on("change", function(){
                                                    toggleFieldToDisable();
                                                });
                                            });
                                            
                                            function setFieldDisabled(fin, disabled){
                                                if(disabled){
                                                    spjs.dffs.doReadOnly([fin]);
                                                }else{
                                                    spjs.dffs.undoReadOnly([fin]);
                                                }
                                            }
                                            
                                            function toggleFieldToDisable(){
                                                let allYes = true;
                                                arrOfChoiceFields.forEach(fin => {
                                                    if(getFieldValue(fin) !== "Yes"){
                                                        allYes = false;
                                                    }
                                                });
                                                setFieldDisabled("Requesting_x0020_an_x0020_Except",allYes);
                                            }
                                            
                                            // Trigger on page load
                                            toggleFieldToDisable();
                                            

                                            Alexander

                                          • #38588
                                            Alexander Bautz
                                            Keymaster

                                              Not over to your other question. First you cannot rely on Chat GPT knowing how to write the correct code – It might be good for writing general code, but specific to the methods used in DFFS it just isn’t. There is no method in DFFS called spjs.dffs.getListItems or spjs.dffs.hideTab / showTab…

                                              Here is the correct code using the methods available in DFFS:

                                              function checkUserRoleAndToggleTab() {
                                                  // Query the Roles list for current user
                                                  let res = spjs.utility.queryItems({
                                                      listName: "Roles",
                                                      query: "<Where><Eq><FieldRef Name='Person' LookupId='TRUE' /><Value Type='Integer'>" + _spPageContextInfo.userId + "</Value></Eq></Where>",
                                                      viewFields: ["Role"]
                                                  });
                                                  var hideTab = false;
                                                  if (res.count > 0) {
                                                      var role = res.items[0].Role;
                                                      // Check if role is "Owner"
                                                      if (role && role.trim().toLowerCase() === "owner") {
                                                          hideTab = true;
                                                      }
                                                  }
                                                  if (hideTab) {
                                                      spjs.dffs.toggleVisibleTab("test", false);
                                                  } else {
                                                      spjs.dffs.toggleVisibleTab("test", true);
                                                  }
                                              }
                                              
                                              // Run the function
                                              checkUserRoleAndToggleTab();
                                              

                                              You can find more information about the CRUD methods in the classic version of DFFS here: https://spjsblog.com/forums/topic/query-update-delete-an-item-in-javascript/

                                              Alexander

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