0

I'm working on a 2013 SP site and do not have the ability to use any program with any cloud based capabilities, or Designer because it'll be obsolete.

I have two lists.

One of the columns overlaps both lists and holds an ID number (by overlap I mean that ID 45 on list 1 is the same item as ID 45 of list 2, it just holds different information because list 2 is indicating what happened to some of the items from list 1 after the events of list 1)

The first list has a multiple selection choice column.

In the second list, I would like it to recognize the ID relationship and pull the data from the multiple selection choice column in the first list so I don't have to re enter the same data that was already entered in list 1.

I have tried searching but I can't seem to find something for this particular situation. The lookup column doesn't work and I don't have the option to create a calculated column for the multiple selection choice column either.

Any ideas?

2
  • Lookup columns does not support extending choice columns, read here. Feb 10, 2022 at 15:30
  • SharePoint Designer can still be downloaded and used, especially with 2013 SharePoint, assuming you are able to install applications on your system. Feb 13, 2022 at 19:49

1 Answer 1

0

Out of the box SharePoint won't do what you are looking for, as stated in other comments.

However, it is not hard to handle this with JavaScript added to the list.

The following should do what you are looking for.

You will still need to do a bit more work as listed below. But nothing you can't figure out with some more searching on StackExchange/StackOverflow or Google.

It makes a few assumptions:

  1. You know the display names of both lists. (This example assumes that they are called ListA and ListB.)
  2. That you always create the same ID in the second list as in the first.
  3. That you have JSON Lite configured on your SharePoint servers. (See https://sympmarc.com/2016/05/02/making-your-rest-calls-simpler-by-changing-the-metadata-setting/), if not you will need to rework the functions to handle verbose's way of returning the object.
  4. That you use ES6 javascript. It isn't hard to rewrite these functions into an earlier version of ES.
  5. You know how to add a Content Editor WebPart to your list's Form.aspx files.
  6. Need to create an html page to host the code below and provide a button that can run the main function. Perhaps some more code to grab the current ID number and inject it into the main function.
    // Utility wrapper for fetch
    async function fetchWrapper(url, options, custom_err_msg) {
        if (!url) {
            throw new Error("url is missing");
        }
        let opt;
        if (options) {
            opt = options;
        } else {
            opt = {
                method: "GET",
                // mode: "no-cors",
                credentials: "include",
                headers: {
                    "Content-Type": "application/json;odata=nometadata",
                    Accept: "application/json;odata=nometadata",
                },
            };
        }
        return fetch(url, opt)
            .then((resp) => {
                if (!resp.ok) {
                    throw new Error(resp.statusText);
                }
                // HANDLE not json
                try {
                    const json = resp.json();
                    return json;
                } catch (error) {
                    console.error(error);
                    return resp.text();
                }
            })
            .then((data) => {
                return data;
            })
            .catch((err) => {
                // HANDLE errors and custom error messages, must be a string
                if (custom_err_msg && typeof custom_err_msg === "string") {
                    console.error(`${custom_err_msg}`, err);
                    return `${custom_err_msg}\n${err}`;
                } else {
                    return err;
                }
            });
    }
    
    async function getDigest(){
        let url = `${_spPageContextInfo.webAbsoluteUrl}/_api/contextInfo`;
        return fetch(url,{
            method:'post',
            credentials:'include',
            headers:{"Accept":"application/json;odata=nometadata"}
        })
        .then(res => {
            return res.json();
        })
        .then(data => {
            return data;
        })
        .catch(error => console.error(error));
    }
    
    function itemGet(id){
        const url = "/_api/web/lists/getbytitle('ListA')/items("+id+")?$select=MultiChoice"
        const result = fetchWrapper(url);
        return result.then((resp) => {
            console.log(resp);
            return resp;
        })
    }
    
    function itemValid(id){
        url = "/_api/Web/Lists/getbytitle('ListB')/items("+id+")"
        const result = fetchWrapper(url);
        return result.then((resp)=> {
            console.log(resp);
            return resp.length !== 0 ? true : false;
        })
    }
    
    async function itemUpdateSecondList(id,data){
        const url = "/_api/Web/Lists/getbytitle('ListB')/items("+id+")"
        let body = JSON.stringify(data);
        const digest = await getDigest();
        const headers = {
            "Content-Type": "application/json;odata=nometadata",
            Accept: "application/json;odata=nometadata",
            "X-RequestDigest": digest.FormDigestValue,
            'IF-MATCH': "*",
            'X-HTTP-Method': "MERGE"
        };
        const result = fetchWrapper(url, {
            method: "POST",
            credentials: "include",
            body: body,
            headers: headers,
        });
        return result.then((resp) => {
            console.log(resp);
        })
    }
    
    async function main(id){
        const itemExists = await itemValid(id);
        if(itemExists){
            let dataToUpdate = await itemGet(id);
            itemUpdateSecondList(id,dataToUpdate)
        } else {
            console.error("No matching item Id found in second list");
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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