Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid undefined error in batch operation #55

Merged
merged 2 commits into from
Aug 8, 2019

Conversation

yonaichin
Copy link
Contributor

No description provided.

@AleksandrRogov
Copy link
Owner

hi @yonaichin , thank you for a pull request. Can you please provide a sample to reproduce an error you're fixing here? What request you're sending and what data you receive? Thanks.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 96.375% when pulling af2eeae on yonaichin:master into 864b425 on AleksandrRogov:master.

@yonaichin
Copy link
Contributor Author

yonaichin commented Aug 8, 2019

Hi, @AleksandrRogov
I think it's the existing record that causing this problem here.
The batch operation is actually succeeded however the error will show as below.

/dynamics365/node_modules/dynamics-web-api/lib/requests/helpers/parseResponse.js:151
                    if (parseParams[requestNumber].hasOwnProperty('valueIfEmpty')) {
                                                   ^

TypeError: Cannot read property 'hasOwnProperty' of undefined
    at parseBatchResponse (/dynamics365/node_modules/dynamics-web-api/lib/requests/helpers/parseResponse.js:151:52)
    at parseBatchResponse (/dynamics365/node_modules/dynamics-web-api/lib/requests/helpers/parseResponse.js:137:36)
    at parseResponse (/dynamics365/node_modules/dynamics-web-api/lib/requests/helpers/parseResponse.js:187:25)
    at IncomingMessage.<anonymous> (/dynamics365/node_modules/dynamics-web-api/lib/requests/http.js:57:40)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

I was trying to upsert a contact that is associated with the account. However, there's already a contact with the same name which is okay with dynamics 365 I supposed.

  1. Create a contact with the name "John Doe" on dynamics 365 using api or Web.
  2. Then run the code below
const account = {
  name: 'AAAA1',
}
const contact = {
  firstname: 'John',
  lastname: 'Doe',
  jobtitle: 'janitor',
  '[email protected]': 'accounts(00000000-0000-0000-0000-000000000002)'
}

dynamicsWebApi.startBatch()
dynamicsWebApi.upsert('00000000-0000-0000-0000-000000000002', 'accounts', account)
dynamicsWebApi.upsert('732e87e1-1d96-e711-80e4-00155db75426', 'contacts', contact)
dynamicsWebApi.executeBatch() 
  .then(() => console.log('success!'))
  .catch(console.error)

This should create 2 contacts, "John Doe" and the "John Doe" with the job title.
Hope this helps.
Please let me know if there's still anything to add up.
Thanks

@AleksandrRogov AleksandrRogov merged commit 1ab3bd4 into AleksandrRogov:master Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants