populateFieldsInGrid() passing dynamic values

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ibarrandres
Posts: 23
Joined: Wed May 27, 2015

03 Apr 2019

Hello,

I was trying to use this example: (https://spform.com/related-items/add-re ... point-form ) to update the a quick links field with the name opportunity but it seems it only takes static values? If I try to pass the title value which is what I need it submits an empty value.

my code example:

(Example does not work)

Code: Select all

var title = fd.field("Title").value();
fd.populateFieldsInGrid($('.related-items'), {
 Parent: '{CurrentItem}',
 Oportunity: title 
})
(Example Works)

Code: Select all

fd.populateFieldsInGrid($('.related-items'), {
 Parent: '{CurrentItem}',
 Oportunity: 'Some random Title'
})

I am probably doing something silly. Thanks for all the help again!

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

03 Apr 2019

Dear ibarrandres,
You are using a JavaScript object to populate new entries, so it also needs to be updated dynamically.

For example, like this:

Code: Select all

//JS object
var populate = {
 Parent: '{CurrentItem}'
};

//function to update the object
function updatePopulate(){
  populate.FieldName = fd.field("Title").value();
}

//run the function when form opens
updatePopulate();

//run the function when Title is updated
fd.field("Title").change(function(){
  updatePopulate();
});

//use populate object when adding new entries
fd.populateFieldsInGrid($('.related-items'), populate);
Cheers

ibarrandres
Posts: 23
Joined: Wed May 27, 2015

03 Apr 2019

Awesome! That worked. Thank you again. PS. Still looking for a beer delivery service there.... :)

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

19 Jun 2019

I have the same need and used the code above as my template. Can't get it to work. See code below, the item creates in the related list just no "MarkupM" value.

//JS object
var populate = {
Parent: '{CurrentItem}'
};

//function to update the object
function updatePopulate(){
populate.Markup = fd.field("MarkupM").value();
}

//run the function when form opens
updatePopulate();

//run the function when field is updated
fd.field('MarkupM').change(function(){
updatePopulate();
});

//use populate object when adding new entries
fd.populateFieldsInGrid($('.related-items'), populate);

I'm sure it's something easy, just stuck. Thank you in advance!

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

19 Jun 2019

Dear Office365Guy,
This can be a lot of things, but primarily it's likely to be an incorrect Internal Field name. Please, check Internal Name of Markup and MarkupM fields, make sure you are using the correct ones in the code.

To get an Internal Name of the field go to List Settings -> select column you want to check and look at its URL:
InternalNameColumn.png
InternalNameColumn.png (17.04 KiB) Viewed 2825 times
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

19 Jun 2019

The internal field name on the related list is "Markup", the local form field name is "MarkupM". I tested the change event on the form for the "MarkupM" field using a simple alert, it returned the correct value and should have updated the JS object when it called the updatePopulate function. I used the same alert in the updatePopulate function just to verify I'm not crazy. Please correct me / my code :).

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

19 Jun 2019

Does the Parent get populated though? Also, you are using Quick Edit mode, right?
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

19 Jun 2019

Yes, quick edit mode, yes it populates, just not the value for the Markup??? This is on the Edit form.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

19 Jun 2019

Not quite sure then... Is the field available in the selected view? Also, what's the field type that you are trying to populate?
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

21 Jun 2019

Got it, it was a simple field name misspelled. Took some time to find it. Thanks for the sanity check! ;)

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests