Cli-microsoft365: Bug report: Error using command spo listitem add when textfield value only contains numbers

Created on 2 Jan 2020  路  6Comments  路  Source: pnp/cli-microsoft365

Error when add listitem where text field value is numeric like below:

o365 spo listitem add --listTitle "Test" --webUrl "https://xxxx.sharepoint.com/sites/xxxx" --Title "1111"
Error: Cannot convert a primitive value to the expected type 'Edm.String'

Windows 10 CLI version 2.4.0, PowerShell

bug

Most helpful comment

@garrytrinder @waldekmastykarz thanks the quick response and fix. This works fine now in the latest beta version.
I wish the PnP-Sites-Core repo had the same response time, there is a lot of open issues now...

All 6 comments

Thanks for reporting the issue @matsla and sorry for the trouble. We'll investigate it asap

Looks like this issue is caused by the mapRequestBody function, specifically the below block

Object.keys(options).forEach(key => {
    if (excludeOptions.indexOf(key) === -1) {
        requestBody.push({ FieldName: key, FieldValue: (<any>options)[key] });
    }
});

Executing the below command...

o365 spo listitem add --listTitle "Test" --webUrl "https://xxxx.sharepoint.com/sites/xxxx"  --Title "1111"

Passes these options into the function.

{
  webUrl: 'https://xxxx.sharepoint.com/sites/xxxx',
  listTitle: 'Test',
  Title: '1111'
}

The function returns this object as the requestBody which causes the error to be thrown.

[ { FieldName: 'Title', FieldValue: 1111 } ]

@matsla thank you for reporting this, I have raised a PR containing the fix.

@matsla the PR has been merged and this fix is available in the latest beta version of the CLI, which can be installed using npm install -g @pnp/office365-cli@next

@garrytrinder @waldekmastykarz thanks the quick response and fix. This works fine now in the latest beta version.
I wish the PnP-Sites-Core repo had the same response time, there is a lot of open issues now...

Thank you for the kinds words @matsla

Was this page helpful?
0 / 5 - 0 ratings