Auto Complete only if targeted fields are empty

Forums Autocomplete Auto Complete only if targeted fields are empty

Viewing 9 reply threads
  • Author
    Posts
    • #33210
      MikeS
      Participant

      I would like Auto Complete to only populate those fields that are empty when addressed in the setFields section. How could that be accomplished?

      Thanks
      MikeS

    • #33221
      Alexander Bautz
      Keymaster

      I didn’t really have any way to control this in the code, but I have made a small adjustment to the code to let you use the parseFunction to check the current value – and if it is not empty it will set the current value and not the value pulled form the AC.

      Try the attached version (you must rename it from .txt to .js and and replace the file you have in /SPJS/DFFS/plugins).

      Use it like this:

      // the setFields section of your AC function call:
      "setFields": [
          {
              "fromFIN": ["Your_field_name"],
              "joinBy": "",
              "toFIN": "Target_field",
              "parseFunction": "customParseFn",
              "skipIfEmpty": true
          }
      ]

      The parseFunction is added to your Custom JS:

      function customParseFn(val, fin){
          var currVal = getFieldValue(fin);
          var rVal = val;
          if (currVal.length > 0) {
              rVal = currVal;
          }
          return rVal;
      }

      Let me know how this works out.

      Alexander

      Attachments:
    • #33226
      MikeS
      Participant

      Alexander,

      I’ve tried this on New and Edit forms and it is not working as needed. If there are blank fields in the source list record the Template Type is not showing up in my Autocomplete Template selection field. Kind of opposite from what I need. In order to better communicate what is needed I’ve attached a diagram that should help.

      Thanks
      MikeS

      • #33253
        Alexander Bautz
        Keymaster

        Please ensure that the previous version of the script is not cached in your browser by hovering over the “Enhanced with DFFS” link and check the version – it should be 1.6.52.

        Alexander

    • #33266
      MikeS
      Participant

      Yes, version 1.5.52, April 15, 2021, is shown. It is not working properly as described in the diagram above that explains it in more detail.

      Thanks for your help,
      MikeS

      • This reply was modified 3 weeks, 3 days ago by MikeS.
      • #33269
        Alexander Bautz
        Keymaster

        Ah, I think the problem is “skipIfEmpty” in my code snippet – I didn’t realize it was set to true – try it like this:

        "setFields": [
            {
                "fromFIN": ["Your_field_name"],
                "joinBy": "",
                "toFIN": "Target_field",
                "parseFunction": "customParseFn",
                "skipIfEmpty": false
            }
        ]

        Alexander

    • #33274
      MikeS
      Participant

      I changed skipIfEmpty to “false.” That allows me to see the complete list of Template Types in the Autocomplete list Template selection field (proper operation).

      Unfortunately, all fields are still being overwritten in the Autocomplete list, whether blank or not.

      MikeS

      • #33276
        Alexander Bautz
        Keymaster

        I seems to work in my test – try adding a debugger here to “see” what is being set:

        function customParseFn(val, fin){
            var currVal = getFieldValue(fin);
            var rVal = val;
        debugger;
            if (currVal.length > 0) {
                rVal = currVal;
            }
            return rVal;
        }

        The debugger statement will pause the function and bring up the developer console – when it pauses, hover over the function arguments “val” and “fin” and the variables “currVal” and “rVal” to see the value.

        The if(currVal.length > 0) line is supposed to identify that the current form has a value in the field and re-set the value to the one already in the field.

        Let me know what the debug shows.

        Alexander

    • #33281
      MikeS
      Participant

      Custom JS gives me a yellow ! triangle: “Forgotten ‘debugger’ Statement?” Nothing happens when Edit form opened (developer console is not opened).

      MikeS

      • #33283
        Alexander Bautz
        Keymaster

        The triangle is as expected – the debugger statement is only used when debugging and must not be forgotten in a production environment.

        The customParseFn function should be invoked every time you change the AC-field. If it does not you must ensure you have added it in the “parseFunction” parameter in your AC-setup.

        Alexander

    • #33285
      MikeS
      Participant

      The ParseFn function is defined as follows in my CustomJS prior to AC statements:

      function customParseFn(val, fin){
          var currVal = getFieldValue(fin);
          var rVal = val;
           if (currVal.length > 0) {
              rVal = currVal;
             debugger;
          }
          return rVal;
      }

      AC code and sample of SetFields:

      spjs.ac.textField({
       "applyTo": "TemplateType",
       "helpText": "",
       "loadText": "",
       "listGuid": "{redacted}",
       "listBaseUrl": "redacted",
       "showField": "Title",
       "searchFields": ["Title"],
       "filterCAML": "",
       "useREST": false,
       "preloadData":false,
       "filterREST": "",
       "optionDetailFields": [],
       "optionDetailPrefix": [],
       "enforceUniqueValues": false,
       "rowLimit": 30,
       "listOptionsOnFocus": true,
       "minLengthBeforeSearch": 1,
       "reValidateOnLoad": false,
       "allowAddNew": false,
       "isLookupInSelf": false,
       "addNewAdditionalFields": [],
       "multiselect": false,
       "multiselectSeparator": "; ",
       "orderBy": [
          {
       "fin":"Title",
       "ascending":true
      }
           ],
       "clearSetFieldsOnInvalidSelection": true,
      // the setFields section of your AC function call:
       "setFields": [
           {
      			"fromFIN":"Description",
      			"joinBy": "",
      			"toFIN":"Description",
      		    "parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},

      Still not working. Running latest DFFS package.

      MikeS

      • This reply was modified 3 weeks, 2 days ago by MikeS.
      • #33289
        Alexander Bautz
        Keymaster

        Not sure what is wrong, but can you post the complete code you use in your spjs.ac.textField function call so I can try to figure out what is going on?

        Replace any sensitive info with a dummy-value so the code structure is complete.

        Alexander

    • #33291
      MikeS
      Participant

      This file is loaded before executing the Autocomplete Custom JS

      _scripts/PullInformationFromConnectedList.js

      Complete AC code:

      spjs.ac.textField({
       "applyTo": "TemplateType",
       "helpText": "",
       "loadText": "",
       "listGuid": "{redacted}",
       "listBaseUrl": "redacted",
       "showField": "Title",
       "searchFields": ["Title"],
       "filterCAML": "",
       "useREST": false,
       "preloadData":false,
       "filterREST": "",
       "optionDetailFields": [],
       "optionDetailPrefix": [],
       "enforceUniqueValues": false,
       "rowLimit": 30,
       "listOptionsOnFocus": true,
       "minLengthBeforeSearch": 1,
       "reValidateOnLoad": false,
       "allowAddNew": false,
       "isLookupInSelf": false,
       "addNewAdditionalFields": [],
       "multiselect": false,
       "multiselectSeparator": "; ",
       "orderBy": [
          {
       "fin":"Title",
       "ascending":true
      }
           ],
       "clearSetFieldsOnInvalidSelection": true,
       
       // the setFields section of your AC function call:
       "setFields": [
           {
      			"fromFIN":"Fin1",
      			"joinBy": "",
      			"toFIN":"Fin1",
      		    "parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		{
      			"fromFIN":"Fin2",
      			"joinBy": "",
      			"toFIN":"Fin2",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      	    {
      			"fromFIN":"Fin3",
      			"joinBy": "",
      			"toFIN":"Fin3",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		{
      			"fromFIN":"Fin4",
      			"joinBy": "",
      			"toFIN":"Fin4",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		     {
      			"fromFIN":"Fin5",
      			"joinBy": "",
      			"toFIN":"Fin5",
      		    "parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		{
      			"fromFIN":"Fin6",
      			"joinBy": "",
      			"toFIN":"Fin6",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      	    {
      			"fromFIN":"Fin7",
      			"joinBy": "",
      			"toFIN":"Fin7",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		{
      			"fromFIN":"Fin8",
      			"joinBy": "",
      			"toFIN":"Fin8",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      				{
      			"fromFIN":"Fin9",
      			"joinBy": "",
      			"toFIN":"Fin9",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      	    {
      			"fromFIN":"Fin10",
      			"joinBy": "",
      			"toFIN":"Fin10",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      		{
      			"fromFIN":"Fin11",
      			"joinBy": "",
      			"toFIN":"Fin11",
      			"parseFunction": "customParseFn",
                  "skipIfEmpty": false
      		},
      	],
       "debug": false
      }); 
      • This reply was modified 3 weeks, 2 days ago by MikeS.
      • #33294
        Alexander Bautz
        Keymaster

        Thanks,
        If the debugger statement in the function does not actually bring up the developer tools to pause the code I’m wondering if you might have another function with the same name in your custom js? – if so, the last function added will be the one used.

        If you have a duplicate you must change one of the functions and update the name used in the parseFunction parameter in the AC function call.

        Alexander

    • #33296
      MikeS
      Participant

      Nope, I’ve run the AC code above as the only Custom JS code and have placed it after other Custom JS with same results. The Template Type fields always overwrite the AC list fields whether the AC list fields are populated or not.

      MikeS

      • #33303
        Alexander Bautz
        Keymaster

        This is very strange. I have tested a similar setup and cannot reproduce it. Could you send me some screenshots of your custom js, your form where you have the autocomplete and the list where you have the data to fill the autocomplete field and I’ll try to figure out what is going on.

        Send it to the email you receive the forum notifications from.

        Alexander

    • #33306
      MikeS
      Participant

      I will set up two demo lists and see if I can replicate the problem with new lists and go from there.

      MikeS

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