Home › Forums › SPJS-Lookup › display lookup sub-field info on newform for read only use
Tagged: lookup dynamic values
- This topic has 15 replies, 3 voices, and was last updated 6 years, 4 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 25, 2017 at 01:45 #15873
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?
-
February 25, 2017 at 21:00 #15879
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
-
February 28, 2017 at 00:08 #15939
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?
-
February 28, 2017 at 20:15 #15943
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
-
March 7, 2017 at 18:23 #16011
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?
-
March 9, 2017 at 22:02 #16048
I don’t understand exactly what you mean – can you clarify?
Alexander
-
July 6, 2018 at 18:01 #21385
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?
Attachments:
-
July 7, 2018 at 09:58 #21395
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
-
July 16, 2018 at 19:24 #21450
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);
} -
July 17, 2018 at 08:57 #21454
Can you show me the error message?
Alexander
-
July 17, 2018 at 18:38 #21458
Here’s a screenshot:
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);
}); -
July 18, 2018 at 08:31 #21464
Hi,
Please upload the image of the error as an attachment – the link requires a login.Alexander
-
July 18, 2018 at 19:31 #21479
Attached here.
Attachments:
-
July 18, 2018 at 20:15 #21482
I see – please replace / retype all quotes in your code snippet – they are the wrong type – probably messed up with copy and paste.
Alexander
-
July 19, 2018 at 01:10 #21484
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);
});Attachments:
-
July 19, 2018 at 23:28 #21495
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.