none
SP Services AutoComplete using multiple columns and content types RRS feed

  • Question

  • Greetings,

    I have Library "Inbox" where documents land.  I have Default CT = A on this library.  Additional Content Types = B, C, D, E, F. I'm using the Content Organizer to route documents to different libraries. If CT= B, then move document to Library B.  If CT= C, move document to library C etc. 

    I'm using SP Services Autocomplete for SP2013 on prem.  I'm able to use the following code in my upload.aspx form of the "inbox" libary.  It works great except for two content types.  E & F have different columns I wish to use lookups (auto complete for).

    Content Types B, C, D all share the 2 columns (Group Number & Contract Number) and are working great.  The problem is that when I'm triaging documents and choose Content Type E, I don't have Group Name column and Only have Contract number Column. the script fails to work when this happens.  Can I modify the script to say if CT = B, C, D use this code below and if CT = E or F, execute diff code? Forgive my relative inexperience with Jquery and JS.  Thanks!

    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.min.js"></script><script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.js"></script> 
    <script type="text/javascript">
        $(document).ready(function () {
            $().SPServices.SPAutocomplete({
                sourceList: "Policy Administration List",
               sourceColumn: "NMGroupName",
                columnName: "Group_Name",
    	    ignoreCase: true,
                numChars: 2,
                slideDownSpeed: 'fast',
    	    debug: true
            });
        });
    
      $(document).ready(function () {
            $().SPServices.SPAutocomplete({
                sourceList: "Policy Administration List",
                sourceColumn: "nmContractNumber",
                columnName: "Contract Number",
    	    ignoreCase: true,
                numChars: 2,
                slideDownSpeed: 'fast',
    	    debug: true
            });
        });
    </script>


    • Edited by SP Drew Monday, April 10, 2017 9:37 PM
    Monday, April 10, 2017 9:35 PM

Answers

  • A colleague of mine helped figure out a solution using my original script. posting here incase it helps anyone else:
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.min.js"></script>
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.js"></script>
    
    <script type="text/javascript">
    function setGroup()
    	{
    
    	$().SPServices.SPAutocomplete({
                sourceList: "Policy Administration List",
               sourceColumn: "NMGroupName",
                columnName: "Group_Name",
    	    ignoreCase: true,
                numChars: 2,
                slideDownSpeed: 'fast',
    	    debug: true
              });
    	};
      function setContract()
    	{
    	$().SPServices.SPAutocomplete({
                	sourceList: "Policy Administration List",
                	sourceColumn: "nmContractNumber",
                	columnName: "Contract Number",
    	    	ignoreCase: true,
                	numChars: 2,
                	slideDownSpeed: 'fast',
    	    	debug: true
            	});
    	};
    
    function setClaim()
    	{
    	$().SPServices.SPAutocomplete({
                	sourceList: "Claims List",
                	sourceColumn: "nmClaimNumber",
                	columnName: "Claim Number",
    	    	ignoreCase: true,
                	numChars: 2,
                	slideDownSpeed: 'fast',
    	    	debug: true
            	});
    	};
    
    function runAfterEverythingElse(){
    var contentType = $('select[name$="ContentTypeChoice"] option:selected');
    if (contentType.text() == "New Group Document") {
         
       setGroup();
       setContract();
        };
    if (contentType.text() == "Amendments Document") {
        setGroup();
        setContract();
        };
    
    if (contentType.text() == "Claim Document") {
       setClaim();
        };
    };
    _spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
     </script> 
    

    • Marked as answer by SP Drew Thursday, April 20, 2017 6:08 PM
    Thursday, April 20, 2017 6:08 PM

All replies

  • Can you please check the sourceColumn name, it needs to be the StaticName (internal field name)?

    Thanks, Amit Kumar, LinkedIn Profile ** My Blog
    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful

    Tuesday, April 11, 2017 6:08 AM
  • Hi,

    Try to init the auto complete based on content type, here is my sample code for your reference:

     

    <script type="text/javascript" src="/_layouts/15/jquery.plumfromautocomplete/jquery.min.js"></script>
        <script type="text/javascript" src="/_layouts/15/jquery.plumfromautocomplete/jquery.plumFormAutocomplete.js"></script>
        <script type="text/javascript" src="/_layouts/15/SPService/jquery.SPServices-0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
        <script type="text/javascript" src="/_layouts/15/jquery.plumfromautocomplete/jquery-ui-1.10.3/jquery-ui-1.10.3.custom.min.js"></script>
        <link href="/_layouts/15/jquery.plumfromautocomplete/jquery-ui-1.10.3/css/smoothness/jquery-ui-1.10.3.custom.min.css" rel=" stylesheet" />
        <script type="text/javascript">
            $(function () {
                var contentType = $('select[name$="ContentTypeChoice"] option:selected');
                if (contentType.text() == "Document") {
    
                    //get control for autocomplete field
                    var fieldControl = $.getFieldControl('GroupNumbe');
    
                    //call autocomplete plugin for field control
                    fieldControl.plumFormAutocomplete({
                        sourceList: 'Employee',
                        sourceMatchField: 'Company',
                        labelSeparator: ', ',
                        fillConcatenatedLabel: false,
                        fieldsMapping: [{ sourceField: 'Company', targetField: 'GroupNumbe' }]
                    });
                } else {
                    //get control for autocomplete field
                    var fieldControl = $.getFieldControl('ContractNumber');
    
                    //call autocomplete plugin for field control
                    fieldControl.plumFormAutocomplete({
                        sourceList: 'Employee',
                        sourceMatchField: 'EmployeeID',
                        labelSeparator: ', ',
                        fillConcatenatedLabel: false,
                        fieldsMapping: [{ sourceField: 'EmployeeID', targetField: 'ContractNumber' }]
                    });
                }
            })
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 11, 2017 8:03 AM
  • Hi Lee,

    I tried your code using the plumForm Autocomplete JS.  I have not had any success.  I went to the network tab in IE and all of the scripts are loading properly which is good.  Pretty sure my field internal names are correct so not sure where to go from here.  some additional information if helpful. the column names are site columns so the internal names of the source list should match the destination (library). 

    Here's the code I'm using so hope you can spot something I may have overlooked. 

    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/plumForm/jquery.min.js"></script>
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/plumForm/jquery.plumFormAutocomplete.js"></script>
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/plumForm/jquery.SPServices.min.js"></script>
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/plumForm/jquery-ui-1.10.3/jquery-ui-1.10.3.custom.min.js"></script>
    <link href="/_catalogs/masterpage/JS/plumForm/jquery-ui-1.10.3/css/smoothness/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
    	
    	var contentType = $('select[name$="ContentTypeChoice"] option:selected');
                if (contentType.text() == "New Group Document") {
    
    	 //get control for autocomplete field
                    var fieldControl = $.getFieldControl('NMGroupName');
    
                    //call autocomplete plugin for field control
                    fieldControl.plumFormAutocomplete({
                        sourceList: 'Policy Administration List',
                        sourceMatchField: 'NMGroupName',
                        labelSeparator: ', ',
                        fillConcatenatedLabel: false,
                        fieldsMapping: [{ sourceField: 'NMGroupName', targetField: 'NMGroupName' }]
                    });
                } else {
                    //get control for autocomplete field
                    var fieldControl = $.getFieldControl('nmContractNumber');
    
                    //call autocomplete plugin for field control
                    fieldControl.plumFormAutocomplete({
                        sourceList: 'Policy Administration List',
                        sourceMatchField: 'nmContractNumber',
                        labelSeparator: ', ',
                        fillConcatenatedLabel: false,
                        fieldsMapping: [{ sourceField: 'nmContractNumber', targetField: 'nmContractNumber' }]
                    });
                }
            })
    </script>
    Please advise.

    Monday, April 17, 2017 9:28 PM
  • Hi,

    You could try to debug the script and check does the autocomplete trigger correctly.( here I use IE developer tool F12, you could check more details here https://msdn.microsoft.com/en-us/library/gg589507(v=vs.85).aspx )

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 18, 2017 4:51 AM
  • A colleague of mine helped figure out a solution using my original script. posting here incase it helps anyone else:
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.min.js"></script>
    <script type="text/javascript" language="javascript" src="/_catalogs/masterpage/JS/jquery.SPServices-2014.02.js"></script>
    
    <script type="text/javascript">
    function setGroup()
    	{
    
    	$().SPServices.SPAutocomplete({
                sourceList: "Policy Administration List",
               sourceColumn: "NMGroupName",
                columnName: "Group_Name",
    	    ignoreCase: true,
                numChars: 2,
                slideDownSpeed: 'fast',
    	    debug: true
              });
    	};
      function setContract()
    	{
    	$().SPServices.SPAutocomplete({
                	sourceList: "Policy Administration List",
                	sourceColumn: "nmContractNumber",
                	columnName: "Contract Number",
    	    	ignoreCase: true,
                	numChars: 2,
                	slideDownSpeed: 'fast',
    	    	debug: true
            	});
    	};
    
    function setClaim()
    	{
    	$().SPServices.SPAutocomplete({
                	sourceList: "Claims List",
                	sourceColumn: "nmClaimNumber",
                	columnName: "Claim Number",
    	    	ignoreCase: true,
                	numChars: 2,
                	slideDownSpeed: 'fast',
    	    	debug: true
            	});
    	};
    
    function runAfterEverythingElse(){
    var contentType = $('select[name$="ContentTypeChoice"] option:selected');
    if (contentType.text() == "New Group Document") {
         
       setGroup();
       setContract();
        };
    if (contentType.text() == "Amendments Document") {
        setGroup();
        setContract();
        };
    
    if (contentType.text() == "Claim Document") {
       setClaim();
        };
    };
    _spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
     </script> 
    

    • Marked as answer by SP Drew Thursday, April 20, 2017 6:08 PM
    Thursday, April 20, 2017 6:08 PM