display lookup sub-field info on newform for read only use

Forums SPJS-Lookup display lookup sub-field info on newform for read only use

This topic contains 5 replies, has 2 voices, and was last updated by  Alexander Bautz 5 months, 2 weeks ago.

  • Author
    Posts
  • #15873

    Jeff Lynch
    Participant

    Here is my situation – I have a list with info about employees – I have a separate list for change requests, I want the user (Admin) to select an employee in a lookup on the new change form, have it display the current info from the employee list on that page so they can then fill in the “New” values – which then go through an approval process.

    If this is already answered somewhere please point me that way but how can I have the newform, and/or edit form display those sub-values for the employee lookup on a list new/edit form?

  • #15879

    Alexander Bautz
    Keymaster

    Hi,
    Look at this article.

    This is not “certified” for DFFS, but you should be able to load the “PullInformationFromConnectedList.js” file above the Custom JS and add the function call to the Custom JS.

    Alexander

  • #15939

    Jeff Lynch
    Participant

    this works great, is there a fast easy way to add a button to edit the parent list in a dialog box from the newform and editform?

  • #15943

    Alexander Bautz
    Keymaster

    You can use this method to open a dialog:

    function openCustomDialog(id){
    	var url = "http://contoso.com/sites/your_site/your_list/EditForm.aspx?ID="+id;
    	SP.UI.ModalDialog.showModalDialog(
    		{
    			"url":url,
    			"dialogReturnValueCallback":customCallbackFunc
    		}
    	);
    }
    
    function customCallbackFunc(ok){
    	if(ok){
    		alert("Clicked OK");
    	}else{
    		alert("Clicked Cancel");
    	}
    }

    If you add the above code to the Custom JS, and then adapt the “PullInformationFromConnectedList.js” code to make a link like this:

    function getListItemFromLookup(id,argObj){
    	var arrFin, arrDispName, item, result, val;
    	arrFin = [];
    	arrDispName = [];
    	// Split the array in separate arrays for InternalName and DisplayName
    	$.each(argObj['arrFinAndDispName'],function(i,item){
    		split = item.split('|');
    		arrFin.push(split[0]);
    		arrDispName.push(split[1]);
    	});
    	// Get the correct list item	
    	item = spjs_getItemByID({"listName":argObj['ListGuid'],"id":id,"viewFields":arrFin});
    	if(item!=null){
    		result = [];
    		$.each(arrFin,function(i,fin){
    			if(fin === "ID"){
    				val = "<span style='cursor:pointer' onclick='openCustomDialog("+item.ID+")'>Link</span>";
    			}else{
    				val = item[fin];
    			}			
    			if(val==null){
    				val=' ';
    			}else if(val.split(';#').length>1){
    				val = val.split(';#')[1];
    			}
    			result.push({"fin":fin,"disp":arrDispName[i],"val":val});
    		});
    		return result;
    	}else{
    		return false;
    	}
    }

    Then add the ID column like this to the argumentObj:

    var argumentObj = {
        'arrFinAndDispName':["Title|Tittel","ID|Edit item"],
        'ListGuid':"{d6d798c7-9724-42ff-81c4-241f09707863}",
        'LookupFIN':'LookupColumn1'
    };

    Hope this gets you started.

    Alexander

  • #16011

    Jeff Lynch
    Participant

    one issue with the first part, if you open the display form first and then click the edit from there, it does not work, it appears the return path after the ID breaks it, any fix for that?

  • #16048

    Alexander Bautz
    Keymaster

    I don’t understand exactly what you mean – can you clarify?

    Alexander

You must be logged in to reply to this topic.