Creating a fresh SharePoint list with a reference column through the Graph API - A step-by-step guide

Ahoy mateys! Shiver me timbers, there be a typo here!

I be toiling away on a server side service aimed at crafting a new Sharepoint List Using Graph API. This list be intended for use by humans, so all I need be to create the structure.

Me hearties, when attempting to fashion a simple list with merely text fields, all sails be set fair and true. But now comes the challenge of adding a lookup column to the list. This be a lookout column that ought to refer back to another list in the same site, allowing the scallywags to select one item from the source list.

To be precise, this be the code I be grappling with at present. I have ventured down many other paths I found online, but alas, no treasure to show for it.

const bootyList = {
      displayName: `treasurelist`,
      columns: [
        { name: "Entity", text: {} },
        { name: "Justification", text: {} },
        { name: "Deescription", text: {} },
        {
          name: "MacroExpensiveItem",
          lookup: {
            listId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            columnId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          },
        },
        { name: "Note", text: {} },
      ],
      list: {
        template: "genericList",
      },
    };

    const newBootyList = await graph
      .api(newListURL)
      .version("beta")
      .post(bootyList);

For secrecy reasons, I buried the listId and columnId, but rest assured, those ids be correct as Davy Jones' locker in my real code.

Hoist the colors! Executing this code creates the list and sets the column as Lookup, yet the field does not point back to the source list and remains bare as a bone.

Arrr, be it even possible to craft such a lookup field?

I've tried multiple solutions to no avail. I've sailed using only the listId, attempted cloning a base list, and don't even remember how many other maneuvers.

Answer №1

It is imperative to utilize either columnName or primaryLookupColumnId in place of columnId. The property columnId does not exist.

const financeList = {
      displayName: `testlist`,
      columns: [
        { name: "Entity", text: {} },
        { name: "Justification", text: {} },
        { name: "Deescription", text: {} },
        {
          name: "MacroExpenseItem",
          lookup: {
            listId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            columnName: "column_name",
          },
        },
        { name: "Note", text: {} },
      ],
      list: {
        template: "genericList",
      },
    };

    const newFinanceList = await graph
      .api(newListURL)
      .version("beta")
      .post(financeList);

Resource:

Lookup column

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concealing and revealing all dropdownlist elements using Asp.net javascript

Hey there, I'm working on an ASP.NET project and I have a dropdownlist that contains multiple items. I am looking to implement functionality where I can hide or show all the items in the dropdownlist based on user interaction. <asp:DropDownList id ...

Insert a fresh item into the existing unordered list

Every time I enter something in the prompt, it shows up as "undefined". What I actually want is for whatever I type into the prompt to be added as a new list item. For instance, if I type "Food" in the prompt, I expect to see "Food" appear on the second li ...

Converting a React element using JSON.stringify results in transforming it into a JavaScript object

I have an element in React called testReactElement that I want to display on the screen. I also want it to persist even after the user closes the tab and opens it again, so I decided to store it in localStorage. To add a React element to localStorage, I fi ...

I am experiencing difficulty in retrieving the result for the following code snippet

I'm currently attempting to retrieve data for my chart from a data.csv file. <!DOCTYPE html> <html> <head> <title>D3 test</title> <style> .grid .tick { ...

jQuery .load() pause, content loading

Can anyone provide assistance with achieving the desired effect of fading out the #portfolio-wrapper, then loading the portfolio2.html and fading it in? Currently, the load function is executing before the fadeOut operation. Any help would be greatly app ...

Is it possible for JavaScript to style two different phone number elements on a single page?

After successfully creating a script that auto formats an element by ID on my website, I encountered an issue with multiple forms. The script works perfectly for a single element, but when I attempted to change it to target elements by class name using get ...

What is the reason for the inability to debug the JavaScript function from an ASPX file?

I need to insert a debug point in my JavaScript function within the ASPX source file. However, when I write the keyword "debugger" inside the function and click the update button, the debugger is not being triggered. All I want is for the debugger in the ...

Execute an AJAX request in JavaScript without using string concatenation

On my webpage, users input code in a programming language which can be over 2000 characters long and include any characters. When they press the send button, the code is sent to a server-side script file using JavaScript AJAX. Currently, I am using the fo ...

We could not find the requested command: nodejs-backend

As part of my latest project, I wanted to create a custom package that could streamline the initial setup process by using the npx command. Previously, I had success with a similar package created with node.js and inquirer. When running the following comma ...

What are the shortcuts for navigating to the next or previous word in a textarea?

Is there a way to navigate the cursor to the next or previous word within a textarea using Javascript? I want to implement similar functionality to the Emacs commands "forward one word" and "back one word" in an HTML textarea. I have successfully retrieve ...

Mastering the use of getText() in Protractor with Page Object Model in Javascript

Having trouble retrieving specific values from my page object. The getText() method is returning the entire object instead of just the text, likely due to it being a Promise. I can provide my code if necessary, but I'm aiming to achieve something sim ...

Saving the state of checkboxes in Angular Material

I am trying to figure out a solution for storing checkbox values, specifically whether they have been checked before or not. For example, I have this dialog: https://i.sstatic.net/c16Ju.jpg After clicking on a checkbox and then clicking Save, the checkbox ...

Error encountered when attempting to insert data into a PostgreSQL database using Node.js and Sequelize

I'm currently using the node sequelize library to handle data insertion in a postgress database. Below is the user model defined in the Users.ts file: export class User extends Sequelize.Model { public id!: number; public name: string; public ...

When using Vimeo's JS API, the player.loadVideo() method will revert the player's settings back to their default options

Using Vimeo's player.js API, I'm setting options on the player to disable the title upon initialization: var options = { id: 59777392, title: false }; var vimPlayer = new Vimeo.Player('myDiv', options); The video player correc ...

When JSON data is copied and displayed in Node.js or JavaScript, it appears as a string

I have written a code to copy one JSON file into another JSON file. Here is the code: function userData(){ fs.copyFile( path.join(process.cwd(), "user/access.json"), path.join(process.cwd(), "client/access.json"), ...

Exploring AngularJS $compile and the concept of scoping within JavaScript windows

I've encountered a scoping issue with the use of this inside an angular-ui bootstrap modal. The code below functions perfectly outside of a modal, but encounters problems when run within one: var GlobalVariable = GlobalVariable || {}; (fun ...

Error encountered while running dev in Next.js: Unexpected JSON token 'u' at position 0

Recently, I decided to dive into learning Next.js and sought out resources like the Youtube Video Next.js Crash Course by Traversy Media and the Next.js Official Documentation for guidance. Following the tutorials, I added the simple code snippet below to ...

Enabling auto-expansion for textareas with every keystroke

Currently, I have implemented the following script: jQuery.each(jQuery('textarea[data-autoresize]'), function() { var offset = this.offsetHeight - this.clientHeight; var resizeTextarea = function(el) { jQuery(el).css('h ...

Creating a URL using Form Fields with Javascript or jQuery - Reg

Creating a Custom URL with Form Fields using JavaScript or jQuery I am looking to generate an external link by incorporating a form with a dynamic variable as shown below: (Where 2500 can be customized based on user input) The final URL will be display ...

Creating a javascript function to update content on click

Recently, I've been designing a webpage and encountered an issue. I want the text in a specific area to change whenever a user clicks on a link. Below is the code snippet related to the section I want to modify using a JavaScript function. <div id ...