Realtime update of Related Items
Apologies if this has been asked before and answered:
I have a related items view to show additional items related to a Lookup field, I would like this view to work in real time so that on the New form once the selection is made in the Lookup field the related item view populates and in the Edit form if the Lookup is changed the related item view will update to match.
I am assuming this can be done through an on change function, but what would the actual function be?
fd.field('Contact_x0020_Name').change(?function?);
Thanks for any assistance
I have a related items view to show additional items related to a Lookup field, I would like this view to work in real time so that on the New form once the selection is made in the Lookup field the related item view populates and in the Edit form if the Lookup is changed the related item view will update to match.
I am assuming this can be done through an on change function, but what would the actual function be?
fd.field('Contact_x0020_Name').change(?function?);
Thanks for any assistance
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Here is the article you need - https://spform.com/related-items/dynami ... point-form
Cheers
Hi Nikita,
This doesn't seem to work, it doesn't break the form in any way the related item just doesn't update. Let me explain a little more detail on what I wish to achieve: -
I have a Company Name Lookup field on a Form and a Contact Name Lookup Field on the Form, the Contact Name Lookup is filtered to only show Contacts related to the selected Company. I then have a Related Items Viewer, currently only set to pull through the email address of the Selected Contact, in order to get this to display anything at all I had to follow the guidance in this forum post.
viewtopic.php?f=1&t=596&p=4215&hilit=%3 ... lect#p4215
In order to not break the form I amended the code in the article you directed me to the following to use the ID as the Filter field:
// Calling Functions on Form Load
setHash();
fd.field('Contact_x0020_Name').change(setHash);
// Function to filter and refresh Related Items Viewer
function setHash(){
var value = fd.field('Contact_x0020_Name').value();
if (value == '') {
value = 0;
}
value = encodeURIComponent(escape(value)).replace(/\-/g, "%252D");
//set the URL’s hash value.
window.location.hash = "InplviewHash" + $(".relatedIssues [webpartid]").attr("webpartid") + '=FilterField=ID-FilterValue=' + value;
}
I'm not 100% sure its a related item viewer I need and not just a HTML field that I populate with the value of the email as I will need a function to get the value of the email and pass it through to another form and I'm not sure it is possible to get values of a related item viewer?
Thanks
This doesn't seem to work, it doesn't break the form in any way the related item just doesn't update. Let me explain a little more detail on what I wish to achieve: -
I have a Company Name Lookup field on a Form and a Contact Name Lookup Field on the Form, the Contact Name Lookup is filtered to only show Contacts related to the selected Company. I then have a Related Items Viewer, currently only set to pull through the email address of the Selected Contact, in order to get this to display anything at all I had to follow the guidance in this forum post.
viewtopic.php?f=1&t=596&p=4215&hilit=%3 ... lect#p4215
In order to not break the form I amended the code in the article you directed me to the following to use the ID as the Filter field:
// Calling Functions on Form Load
setHash();
fd.field('Contact_x0020_Name').change(setHash);
// Function to filter and refresh Related Items Viewer
function setHash(){
var value = fd.field('Contact_x0020_Name').value();
if (value == '') {
value = 0;
}
value = encodeURIComponent(escape(value)).replace(/\-/g, "%252D");
//set the URL’s hash value.
window.location.hash = "InplviewHash" + $(".relatedIssues [webpartid]").attr("webpartid") + '=FilterField=ID-FilterValue=' + value;
}
I'm not 100% sure its a related item viewer I need and not just a HTML field that I populate with the value of the email as I will need a function to get the value of the email and pass it through to another form and I'm not sure it is possible to get values of a related item viewer?
Thanks
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello, Tony!
Don't get discouraged, as this dynamic filtering can sometimes be tricky to implement. Different fields use different methods, sometimes you miss some important step, etc. But it's more than possible to implement in your case, it can actually get much more complex than that.
So, what you need to do, is follow the article closely to make sure you haven't missed any step. Also, make sure to remove any other filtering from Related Items for now, so it doesn't interfere with the code. I also recommend replacing code with something like this, so you can show us your console output with logs and errors if there are any:
Finally, if this doesn't help, I recommend commenting out all the code and filtering Related Items manually first. You can do it by clicking small arrow near the column name and selecting values you want the column to be filtered by:
Now, this will also add a hash in a similar way as what we are trying to do. You can check the hash in the URL of the page after applying filtering, and you can use this site to decode URL. You only need to check what it says in Filter field and Filter Value, other values are not too important in this case.
Make sure that you do NOT sort the column in ascending or descending order though! This will change the hash and it wouldn't be very useful.
Regarding getting the emails, it's more than possible to do. Here is an example code to loop through Related Items and get all the Titles:
It iterates through the first Related Items control on the form, hence fd.relatedItems(0)... But you can use CSS class to access the specific Related Items control you need instead.
Don't get discouraged, as this dynamic filtering can sometimes be tricky to implement. Different fields use different methods, sometimes you miss some important step, etc. But it's more than possible to implement in your case, it can actually get much more complex than that.
So, what you need to do, is follow the article closely to make sure you haven't missed any step. Also, make sure to remove any other filtering from Related Items for now, so it doesn't interfere with the code. I also recommend replacing code with something like this, so you can show us your console output with logs and errors if there are any:
Code: Select all
// Calling Functions on Form Load
setHash();
fd.field('Contact_x0020_Name').change(function(){
setHash();
});
// Function to filter and refresh Related Items Viewer
function setHash(){
console.log("Setting Hash...");
var value = fd.field('Contact_x0020_Name').value();
if (value == '') {
value = 0;
}
console.log("Contact: " + value);
value = encodeURIComponent(escape(value)).replace(/\-/g, "%252D");
//set the URL’s hash value.
window.location.hash = "InplviewHash" + $(".relatedIssues [webpartid]").attr("webpartid") + '=FilterField=ID-FilterValue=' + value;
}
Make sure that you do NOT sort the column in ascending or descending order though! This will change the hash and it wouldn't be very useful.
Regarding getting the emails, it's more than possible to do. Here is an example code to loop through Related Items and get all the Titles:
Code: Select all
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
for (var i = 0; i < rows.length; i++) {
alert(rows[i].Title);
}
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 10 guests