0

On a custom new form (For List A) I need to populate several fields with data from List B based on a lookup field selection. This needs to be updated each time the user changes the selection of the lookup.

Example: The user selects their name from the drop down and it auto populates their details that are contained in a second list (B) in to the relevant fields. Data is primarily strings however it also includes setting a second lookup field as well.

If able to it would be good to set a person picker field as well however it is not necessary.

I have not used CSR before but from what I have researched it sounds like the best option, please advise if this is not the case.

Current REST Code:

//Get item ID
var e = document.getElementById("ctl00_ctl45_g_aecb3c18_b892_4c95_af79_151459af0ea2_ff911_ctl00_Lookup");
var itemID = e.options[e.selectedIndex].value;
//GET URLS

executor.executeAsync({
url: "http://<site>/<subsite>/_api/web/lists(guid'EEF86BD3-D8B2-48E8-8F04-5634F3C06375')/getitembyid(" + itemID + ")",
method: "GET",
success: successHandler,
error: errorHandler
});
1

You could do it with other ways of adding JavaScript to the page but CSR sure is a more modern style SharePoint programming approach.

You need JavaScript and JSOM or REST knowledge to:

  • Attach a change event to the lookup (JS)
  • handle the change (JS)
    • Read data from list B (JSOM or REST)
    • process data (JS)
    • populate fields in form A (JS no need for jQuery perse)

CSR development made easy (by Andrey Markeev)

  1. Use Chrome Browser
  2. Install the Cisar Plugin developed by Adrey Markeev
  3. Close the F12 Console (if open at all)
  4. Browse to a New Form of your List A
  5. Open F12 Developer Tools
  6. Select the Cisar tab

Now the cool stuff happens
(I have been in this Internet business for 25 years... If I use the word cool .. it IS cool)

  1. Click to add a file
  2. Give it a filename (by default all files are stored in /style library/)
  3. And then its almost magic
    Cisar will analyse the Form and built a CSR Template
  4. All you have to add is your JavaScript logic
  5. On every change you make in Cisar the New Form will update,
    No Save, No reload required
    now that is cool Live coding (eat your heart out Visual Studio)

iCISAR

  • Ah I thought that CSR would handle REST within it. Could you provide some help on how to create the REST call and then put data into the fields? See update for my current REST code – Roland Nov 15 '15 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.