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 15 replies, has 3 voices, and was last updated by  Alexander Bautz 4 months 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

  • #21385

    Eric Dickerson
    Participant

    When using the above to show number fields on another list, the numbers show 14 points past the decimal (54.00000000000000)… however these columns are limited to 2 places past the decimal on the source list. Is there a way to limit the points past the decimal showing?

    • #21395

      Alexander Bautz
      Keymaster

      When using this approach, the data is pulled directly from the DB and doesn’t use the render template applied to the field in the SP UI.

      To fix this you must parse the number in the custom function – for example by using something like this:

      if(!isNaN(val)){
      	val = Number(val).toFixed(2);
      }

      Alexander

  • #21450

    Eric Dickerson
    Participant

    confused on where this code should go… should this be placed in the customJS field where the rest of the code is going? We are getting errors when we set it up like this:

    populateProductInfo();
    function populateProductInfo() {
    var fields = init_fields_v2();
    var argumentObj = {‘arrFinAndDispName’:[‘Diamond_x0020_Plus|Premium Plus’,’Premium|Premium’,’Platinum|Advanced’,’Gold|Mid-Level’,’Silver|Value’,’Budget|Budget’],
    ‘ListGuid’:’BBE30B42-613E-4F1E-93D4-41AC1A96F411′,
    ‘LookupFIN’:’Customer0′};
    init_displayInfo(argumentObj);
    }
    if(!isNaN(‘Diamond_x0020_Plus’)){
    ‘Diamond_x0020_Plus’ = Number(‘Diamond_x0020_Plus’).toFixed(2);
    }

  • #21454

    Alexander Bautz
    Keymaster

    Can you show me the error message?

    Alexander

  • #21458

    Eric Dickerson
    Participant

    Here’s a screenshot:

    js error

    and here is ALL the code currently in our custom js section:

    populateProductInfo();
    function populateProductInfo() {
    var fields = init_fields_v2();
    var argumentObj = {‘arrFinAndDispName’:[‘Diamond_x0020_Plus|Premium Plus’,’Premium|Premium’,’Platinum|Advanced’,’Gold|Mid-Level’,’Silver|Value’,’Budget|Budget’],
    ‘ListGuid’:’BBE30B42-613E-4F1E-93D4-41AC1A96F411′,
    ‘LookupFIN’:’Customer0′};
    init_displayInfo(argumentObj);
    }
    if(!isNaN(‘Diamond_x0020_Plus’)){
    ‘Diamond_x0020_Plus’ = Number(‘Diamond_x0020_Plus’).toFixed(2);
    }

    $(“#dffs_Patient”).find(“select”).change(function(){
    $(“#dffs_patientname”).find(“select”).val($(this).val());
    var sText = $(“#dffs_Patient”).find(“option:selected”).text();
    setFieldValue(“null”,sText);
    });

  • #21464

    Alexander Bautz
    Keymaster

    Hi,
    Please upload the image of the error as an attachment – the link requires a login.

    Alexander

  • #21479

    Eric Dickerson
    Participant

    Attached here.

  • #21482

    Alexander Bautz
    Keymaster

    I see – please replace / retype all quotes in your code snippet – they are the wrong type – probably messed up with copy and paste.

    Alexander

  • #21484

    Eric Dickerson
    Participant

    yes. I noticed that too and changed all, still an error, but a different one, image attached.

    also included is a screenshot that shows the warning on back end on line 10

    below is the plaintext code:

    populateProductInfo();
    function populateProductInfo() {
    var fields = init_fields_v2();
    var argumentObj = {‘arrFinAndDispName’:[‘Diamond_x0020_Plus|Premium Plus’,’Premium|Premium’,’Platinum|Advanced’,’Gold|Mid-Level’,’Silver|Value’,’Budget|Budget’],
    ‘ListGuid’:’BBE30B42-613E-4F1E-93D4-41AC1A96F411′,
    ‘LookupFIN’:’Customer0′};
    init_displayInfo(argumentObj);
    }
    if(!isNaN(‘Diamond_x0020_Plus’)){
    ‘Diamond_x0020_Plus’ = Number(‘Diamond_x0020_Plus’).toFixed(2);
    }

    $(“#dffs_Patient”).find(“select”).change(function(){
    $(“#dffs_patientname”).find(“select”).val($(this).val());
    var sText = $(“#dffs_Patient”).find(“option:selected”).text();
    setFieldValue(“null”,sText);
    });

  • #21495

    Alexander Bautz
    Keymaster

    Sorry, I didn’t realize you had it placed in the spot – look at my comment in the top of this thread and add the

        if(!isNaN(val)){
            val = Number(val).toFixed(2);
        }

    snippet like this:

    $.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];
        }
        if(!isNaN(val)){
            val = Number(val).toFixed(2);
        }
        result.push({"fin":fin,"disp":arrDispName[i],"val":val});
    });

    Alexander

You must be logged in to reply to this topic.