As noted in the title, I'm trying to connect an item from a different list (in a separate SP site) to the item being created/edited in my form. I've been able to look up an item via the Lookup control, but I am trying to stamp some values ("Status" - a dropdown select field, as well as Title and Id) from the lookup record into my form ("PReqStatus" single line text field) both on form load and when the lookup value (PReqLookup) is changed.
What am I doing wrong in my JS and config? Do I need both the .extrafields JS and the Extra fields/Expand or is that breaking things?
@Margo it's a drop-down column, so I've removed the expand fields and the .extrafields JS (and removed the "Category/" from the Extra fields).
For whatever reason, it's still not reading in the "Status" field from my lookup, and is only bringing in the id (65 in this example) and Title ("test- do not place" in this example). Should I expect it to write the Status field back into the array? (screenshot of the text field it's writing to):
I also tidied up the code a little to include the form load within the same fd.spRendered:
fd.spRendered(function() {
var PReqStatusVar = fd.field('PReqLookup').value.Status;
fd.field('PReqStatus').value = PReqStatusVar;
Is there a way to refresh the fields on form load? I tried using this, based on another post:
fd.spRendered(function() {
fd.control('PReqLookup').ready().then(function(control){
fd.control('PReqLookup')._dataProvider.refresh();
});
});
from here: Refreshing a List or Library control
Hi @Nikita_Kurguzov - I'm using the lookup to tie together another record to this one. The specific use case is that we're using this form to manage contractor onboarding, so there are several other forms/records related to this one that I want to keep tied together and present the status within this form - a purchase request (PReq), a vendor request (Vend), etc.
I'm using lookup fields to bring in the title and status of those other forms into here, so as they are approved/processed/updated, I want the statuses of those related records to update within the form (i.e. PReqStatus) on form load.
Dear @Gabegia,
Okay, so how does refresh() help here? Is this parent - child relationship, or something more complicated? What do you want the code to do?
To set control value for the Lookup, you need something like this on form load:
Hi @Nikita_Kurguzov - I don't know Javascript very well (or any other coding language) so I'm just trying different things that I can find until something works =)
It's a parent-child relationship (this is the parent, other forms are children of it) with a 1:1 relationship between them.
I'm trying to make it that when the parent form is opened, the children "Status" fields update to the current status. Right now, they seem to be stamped in the form when the lookup values are populated, but are not updating again after that as the children forms are updated.
Unfortunately, the child lists are on different sites, which is why I can't just use the lookup control/column. The child lists pre-existed the parent, which is one of the reasons we're trying to pull all the children into the parent form.
Dear @Gabegia,
I've just checked, and if you save changes to Child, then the Parent's Lookup control should auto-update when the form opens.
For example, I have Contact List with a Lookup control to an Employee list. If I change Employee name and save, and then open Contact List form, it will auto-update the Lookup value on the form itself (not in the List, this requires to save the form) - is this different for you? Or do you need something else?
I'm finding that my "extra fields" (PReqStatus in the example above) aren't auto-updating. What I'm seeing:
I add a lookup record to the parent form, and am bringing in an "Extra field" of "Status" from the child form (again on a different site), and as an example would be brought in with a "Status" value of "Pending"
I save the form, and the data gets saved to my text field as an array, as expected
The child record is updated so the "Status" field is changed to "Complete"
I open the parent form, and would expect the lookup's extra field of "Status" to show "Complete", but it is still showing "Pending"
Only when I clear the lookup and re-add it does the extra field of "Status" then update to "Complete" as expected
Hopefully that's a little more clear - sorry for the long thread here and thanks for all the help & patience.
Dear @Gabegia,
Now, I understand, please, try the following:
fd.spRendered(function() {
//function to update status
function updateStatus(value){
if(value && value.Status){
fd.field('Title').value = value.Status;
}
}
fd.control('Lookup1').ready().then(function(control){
control.$on('change', function(value){
updateStatus(value)
});
//update on form load
var value = control.value;
updateStatus(value)
});
});