Set Lookup column from Autocomplete

Forums Autocomplete Set Lookup column from Autocomplete

Viewing 3 reply threads
  • Author
    Posts
    • #16996
      Gerard Graham
      Participant

      Hi there

      I’m looking to replace a site Lookup column with Autocomplete in the form but retain the Lookup column. I’ve managed to get the lookup column to set using

      “fromFIN”:[“Title”],
      “joinBy”:””,
      “toFIN”:”lookupOutput”,

      but would rather use the ID of the ‘from’ item in case there are duplicate titles. Can you concatenate text with field values e.g. “ID”+”;#”

      Also, using the title, I can’t set multiple values of the lookup column. Any ideas on that?

      If it isn’t possible I’ll be able to do it in a workflow, but would prefer to keep it all in DFFS.

      Thanks

      Gerry

    • #17001
      Alexander Bautz
      Keymaster

      Hi,
      I checked, and it’s not currently possible to set multiple options in a multi-lookup column if you don’t set all as an array at once. I have changed the code and will post an update to spjs-utility.js, but in the meantime you can put this in the Custom JS so SPJS-AC.js can use it:

      spjs.utility.doSetMultiLookupColumn = function(a){
      	var f = jQspjs(spjs.utility.data.fields[a.fin]), lId;
      	f.find("option:selected").removeAttr("selected");
      	if(f.find('select:first option:first').prop('spjs') !== "1"){
      		f.find('select:first option:first').prop('selected', false);
      	}
      	if(!jQspjs.isArray(a.newVal)){
      		if(typeof a.newVal === "string"){
      			a.newVal = a.newVal.split(",");
      		}else{
      			a.newVal = [a.newVal];
      		}
      	}
      	jQspjs.each(a.newVal,function(i,val){
      		if(typeof val === "object"){
      			lId = String(val.get_lookupId());
      		}else{
      			lId = String(val);
      		}
      		if(String(parseInt(lId,10)) === String(lId)){
      			f.find('select:first').find("option").filter(function() {
      				return jQspjs(this).val() === lId; 
      			}).prop('selected', true);
      		}else{
      			f.find('select:first').find("option").filter(function() {
      				return jQspjs(this).text() === lId; 
      			}).prop('selected', true);
      		}
      	});
      	f.find(":button:first").prop("disabled",false).trigger("click");
      	spjs.utility.updateReadonlyValue(a,true);
      };

      You should now be able to use “ID” in the “fromFIN” field in SPJS-AC.

      Let me know how this works out.

      PS: If you use an older version of DFFS you might need to change “jQspjs” with “jQuery” in the snippet above.

      Alexander

    • #17538
      Gerard Graham
      Participant

      Hi there

      Sorry for the delay in responding. I’ve added the code above but no joy. Probably missing something. I am getting the message

      “You cannot use the “setFields” section in the configuration when you are using the “multiselect” option.”

      I wasn’t sure if your reply said that it couldn’t but that the new code would allow it.

      THanks as ever

      Gerry

    • #17557
      Alexander Bautz
      Keymaster

      Hi,
      If you are using the AC in multi-select-mode you cannot use the “setFields” section as the script wouldn’t know which item to pull the data from so it’s unfortunately not possible to use with multiselect.

      Alexander

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