Create list item inside a folder

Hi all, I'm struggling with the creation of a new list item inside an existing folder. I've tried this but always get an error telling that the property Title (Or whatever I select) doesn't exists in Type 'SP.ListItemFormUpdate':

Code

const listFolderPath = "https://xxxxx.sharepoint.com/sites/xxxxxx/Lists/xxxxx/"+folder.toString();
pnp.sp.site.rootWeb.lists.getByTitle('Asistencia').addValidateUpdateItemUsingPath([
     {Title: "Asistencia", Asistencia: "OK", AsistenteId: item.Miembro.ID, MinutaId: Minuta}],
     listFolderPath)

Error:

Uncaught (in promise) Error: Error making HttpClient request in queryable [400] Bad Request ::> {"odata.error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"es-ES","value":"La propiedad 'Title' no existe en el tipo 'SP.ListItemFormUpdateValue'. Aseg\u00farese de que solo usa nombres de propiedad que se definen por el tipo."}}}

Also notice that I have a list control binded to this list in the form and with the correct folder as root folder. I was wondering if it is possible to create this item directly from the control. I've seen it has an "_additem" function, it is possible to create this element with this function?

Thanks in advance

Hello @Pedro,

Welcome to Plumsail Community!

You can create an item and then move it to the folder using the code:

let folderUri = '/folderName';
let listUri = '/sites/SiteName/Lists/ListName';


pnp.sp.web
    .getList(listUri)
    .items.add({
        Title: 'new'
    })
    .then((item) => {
        return pnp.sp.web
            .getFileByServerRelativeUrl(`${listUri}/${item.data.Id}_.000`)
            .moveTo(`${listUri}${folderUri}/${item.data.Id}_.000`);
    })
    .then(console.log)
    .catch(console.log);

Thank you @mnikitina!,
this workaround forces to assign permissions in root folder to the users. There is no other way to do it?
The function I'm trying, is not an option?

regards.

@Pedro,

You can try out this code:

const webUrl = _spPageContextInfo.webAbsoluteUrl;

const listPath=webUrl+"/Lists/ListName";
const folderName="folder name";

pnp.sp.site.rootWeb.lists.getByTitle("ListName").addValidateUpdateItemUsingPath([
    { FieldName: 'Title', FieldValue: 'Value1'}]    
  ,`${listPath}/${folderName}`).then(console.log);

Thank you @mnikitina it works!, but I'm not able to update a user field that I have in this list.
I tried using ID and Name (i:0#.f|membership|xxxxx@xxxx.com)
How do I need to pass this parameter?

pnp.sp.site.rootWeb.lists.getByTitle("Assist").addValidateUpdateItemUsingPath([
        { FieldName: 'Title', FieldValue: 'Value1' },
        { FieldName: 'User', FieldValue: User.toString() },
        ]
      ,`${listPath}/${folderName}`).then(console.log);

Thanks

@Pedro,

You can use this code to populate Person or Group field:

{FieldName: 'User', 
FieldValue: JSON.stringify([{"Key": "i:0#.f|membership|"+"UserEmail"}])}

Now is perfect, thank you @mnikitina!

1 Like