I have a major requirement from my manager where in he needs to build a small tool through SharePoint.
I have a list Consisting of various columns, now all i want to do is to pick up data from List A and bring it in List B but based on some condition.
So, in List A i have a persons name, project name,Planned Start Date , Planned End Date , Actual Start Date , Actual End Date.
What i want to do in List B is when a person selects name of the person from Person name drop down all these columns should be available in the form and data should be filled up in the given fields on selection of Person name and Only Actual Start Date and Actual End Date should be editable.
Could i just know as to ,how to get he data based on name of person from one of the list and if yes, how can it be done?
1 Answer
It prett much depends on how you are retrieving that info.
I'll assume you use RestApi in which case you can get list items with a filter (based on your description of columns i assume you have a field called PersonsName or something similar).
The filter looks like this -> /_api/web/lists/getbytitle('YOURLIST')/items?$filter=PERSONFIELD eq ‘PERSON NAME FROM DROPDOWN'
This way you will only get items in which the "PERSONFIELD" is someones name. You can then use jquery onclick on the dropdown and fire the ajax call to restapi with that filter.
You can read more on filtering here -> https://www.c-sharpcorner.com/article/sharepoint-2013-using-rest-api-selecting-filtering-sortin/
You can see how you can get list items from here -> https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest
var siteUrl = "yourtenant.sharepoint.com/teams/yoursite"
$.ajax({
url: siteUrl + "/_api/web/lists/getbytitle('YOURLIST')/items?$filter=PERSONFIELD eq ‘PERSON NAME FROM DROPDOWN'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
apiResultList = data.d.results; // Returns JSON collection of the results
},
error: function (data) {
alert("Error: " + data);
}
});
the var apiResultList
is global and you can access it to see its contents in the browser console.
-
Hi Dante so what i want is to populate data in new/edit form based on person selected from drop down which be 'Employee Name'. So, lets say in the new form there is employee name and as i select the name, all the other fields should be populated. How can this be done? Oct 4, 2018 at 14:06
-
I've update my answer with one more link. What you will need to do is -> Get list items (with a filter) and save them into an object. After that you can access that object and append the info in the new form. Unfortunately what you are asking for is a bit longer than a simple answer. You will need to know jQuery for ajax calls & to be able to append text into the form (in case you dont). I'll add a simple example for you to get started.– Dante R.Oct 4, 2018 at 14:21
-
In the above example i am able to return only one person name. What if i want to retrieve the whole person field data into the object and then append it to a drop down in the form? Could you kindly help me with the appending of data to a form field be it dropdown or text field or date field?? Oct 5, 2018 at 7:09
-
As i said above, your question is "too big" for an answer here. Look into how to get the items in the links i've added. You use that and retrieve all items -> create the dropdown field and then you can either query again or use the object that you've already retrieved. If you remove
?$filter=PERSONFIELD eq ‘PERSON NAME FROM DROPDOWN'
it will get all items– Dante R.Oct 5, 2018 at 7:11 -