Hello all.
I've been working on changing some of our forms, moving away from SP List "attachments" and toward Document Library uploads.
On this form, I have four List or Library controls: Comments (Discussion List), StemMediaUpload (DL), OptionsMediaUpload (DL), and ReferenceMediaUpload (DL). The only one that works is the List-to-List (Comments).
SUCCESS
Passing values from a Parent SP List to a Child SP List as shown in the Discussion illustration below here.
CODE FOR LIST (works)
//Populate fields of a new List or Library record with the values from the parent form
fd.spRendered(function() {
//prepopulating fields of a new List or Library record with the values from the parent form
fd.control('Comments').$on('edit', function(editData) {
//Check that this is a new record
if (editData.formType === 'New') {
//Prepopulating Commentor field
editData.field('Commentor').ready(function() {
editData.field('Commentor').value = fd.field('WriterTxt').value;
});
}
});
});
PROBLEM
I can't pass all values from a Parent SP List to a Child SP Document Library. I have tried a variation of this with no luck. I have also tried many other combinations. I know I missing something fundamental as my values do not pass from Parent to Child. UPDATE: I have childMediaType working now but not the other two columns.
I welcome any wisdom here. Many thanks as always.
UPDATE: I was getting confused with the column names the same in the List and DL. I have made some changes to differentiate between the Parent and Child.
ADDED INFORMATION
-
Parent List (on same SP site as DL)
- typeStemMedia - Choice (Fixed: was MediaType in my initial post)
- WriterName - Person or group
- Specialty - Lookup (from List on same SP site as DL & Parent List)
-
Child Document Library (on same SP site as List)
- childMediaType - Choice (Fixed: was MediaType in my initial post)
- childwriterName - Person or group (Fixed: was WriterName in my initial post)
- childSpecialty - Lookup (from List on same SP site as DL & Parent List; Fixed: was Specialty in my initial post)
The Discussion illustration from above is a parent-to-child list workflow and works as desired. The video illustration below is a parent-to-child document library workflow, where two of the three targeted child fields (childwriterName and childSpecialty) fail to populate.
VIDEO ILLUSTRATION
CODE FOR DOCUMENT LIBRARY (does not work)
//Populate fields of a new List or Library record with the values from the parent form
fd.spRendered(function() {
//prepopulating fields of a new List or Library record with the values from the parent form
fd.control('StemMediaUpload').$on('edit', function(editData) {
//var currentUserName = _spPageContextInfo.userDisplayName; is used in a previous block to set the value of 'WriterTxt' to be available for use here
//Check that this is a new record
if (editData.formType === 'New') {
//Prepopulating WriterName field; WriterTxt already populated from Parent List WriterName value
editData.field('WriterName').ready(function() {
editData.field('WriterName').value = fd.field('WriterTxt').value;
});
}
});
});
TROUBLESHOOTING HISTORY UPDATE: I have made adjustments to column names since the initial post so some of these may be out of date. As shown in this example, I have tried replacing any reference to edit with upload and New to Add. Basically, attempting to make SOMETHING work or change to help me understand what is/isn't working.
Tried this:
//Populate fields of a new List or Library record with the values from the parent form
fd.spRendered(function() {
//prepopulating fields of a new List or Library record with the values from the parent form
fd.control('StemMediaUpload').$on('upload', function(filesUploaded) {
//Check that this is a new record
if (editData.formType === 'Add') {
//Populate MediaType field
editData.field('Specialty').ready(function() {
editData.field('Specialty').value = fd.control('Specialty').value;
});
}
});
});
Also tried:
var listOrLibrary = 'StemMediaUpload';
var docLibraryTitle = 'Stem Media';
fd.spRendered(function() {
fd.control(listOrLibrary).$on('filesUploaded',
function(itemIds) {
//get document library by Title
var library = pnp.sp.web.lists.getByTitle(docLibraryTitle);
//go through each uploaded Item Id and set field values
library.getListItemEntityTypeFullName().then(function(entityTypeFullName){
var batch = pnp.sp.web.createBatch();
for(var i = 0; i < itemIds.length; i++){
//specify which fields to update and how
library.items.getById(itemIds[i]).inBatch(batch).update({
WriterName: fd.field('WriterName').value.LookupValue,
Specialty: fd.field('Specialty').value.LookupValue,
MediaType: fd.field('MediaType').value.LookupValue
}, "*", entityTypeFullName);
}
batch.execute().then(function(){
fd.control(listOrLibrary).refresh();
});
});
});
});
And this section based on this post:
WriterName: fd.field('WriterName').value.EntityData.SPUserID,
Specialty: fd.field('Specialty').value.LookupID,
MediaType: fd.field('MediaType').value.LookupID
}, "*", entityTypeFullName);
}
And this based on this post:
var listOrLibrary = 'StemMediaUpload';
var docLibraryTitle = 'Stem Media';
fd.spRendered(function() {
var writerNameId = fd.field('WriterName').value.LookupId;
var specialtyId = fd.field('Specialty').value.LookupId;
var mediaTypeId = fd.field('MediaType').value.LookupId;
fd.control(listOrLibrary).$on('filesUploaded',
function(itemIds) {
//get document library by Title
var library = pnp.sp.web.lists.getByTitle(docLibraryTitle);
//go through each uploaded Item Id and set field values
library.getListItemEntityTypeFullName().then(function(entityTypeFullName){
var batch = pnp.sp.web.createBatch();
for(var i = 0; i < itemIds.length; i++){
//specify which fields to update and how
library.items.getById(itemIds[i]).inBatch(batch).update({
//WriterName: fd.field('WriterName').value.EntityData.SPUserID
WriterName: writerNameId,
//Specialty: fd.field('Specialty').value.LookupID,
Specialty: specialtyId,
//MediaType: fd.field('MediaType').value.LookupID
MediaType: mediaTypeId
}, "*", entityTypeFullName);
}
batch.execute().then(function(){
fd.control(listOrLibrary).refresh();
});
});
});
});