Auto resolve external content type and people picker columns

Home Forums Classic DFFS Auto resolve external content type and people picker columns

Viewing 2 reply threads
  • Author
    Posts
    • #13669
      Alexander Bautz
      Keymaster

        This code snippet was created by Penny Kingston to fix an issue where unresolved external content type columns in a form resulted it a failed postback, and a refresh of the form. This caused problems with emails as these would be sent on the first postback.

        This code attaches a “focusout” event on the input that auto resolves the picker value, and prevents the form from saving if it has not resolved properly.

        I have made some minor adjustments to the code – like adding a 1000 milliseconds delay before applying the code to ensure the picker is ready.

        setTimeout(function(){
            autoResolveECT("ECTTest");
            autoResolvePP("PeoplePickerTest");
        },1000);
         
        function autoResolveECT(a) {
            var b = spjs.$(spjs.utility.data.fields[a]);
            b.find("div[id$='Picker_upLevelDiv']").focusout(function() {
                b.find("a[id$='Picker_checkNames']").click();
            });
        }
         
        function autoResolvePP(a) {
            var b = spjs.$(spjs.utility.data.fields[a]);
            b.find("input.sp-peoplepicker-editorInput").focusout(function() {
                SPClientPeoplePicker.SPClientPeoplePickerDict[b.find("div.sp-peoplepicker-topLevel").attr("id")].AddUnresolvedUserFromEditor(true);
            });
        }
         
        function isPeoplePickerResolved(a) {
            var b = spjs.$(spjs.utility.data.fields[a]), c = true;
            spjs.$.each(SPClientPeoplePicker.SPClientPeoplePickerDict[b.find("div.sp-peoplepicker-topLevel").attr("id")].GetControlValueAsJSObject(), function(a, b) {
                if (false === b.IsResolved){
                    c = false;   
                }
            });
            return c;
        }
         
        function isExternalContentResolved(a) {
            var b = spjs.$(spjs.utility.data.fields[a]), c = "true" === b.find("span.ms-usereditor").attr("value").toLowerCase() ? false : true, d = true;
            b.find("div[id='divEntityData']").each(function(a, b) {
                c = true;
                if ("false" === spjs.$(b).attr("isresolved").toLowerCase()){
                    d = false;   
                }
            });
            return c && d;
        }
         
        function PreSaveAction() {
            return isPeoplePickerResolved("PeoplePickerTest") && isExternalContentResolved("ECTTest");
        }

        This code targets a people picker field named “PeoplePickerTest” and an external content type column named “ECTTest”. Change these names to match your column names.

        Alexander

      • #13709
        Colin
        Participant

          Thanks for sharing! Would it be possible to have this added into DFFS?

        • #13760
          Alexander Bautz
          Keymaster

            I’ll see what I can do about adding it, but I’ll have to do some testing as it might behave a bit different in SP 2010 and 2013 / 2016.

            Alexander

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