gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
280 stars 72 forks source link

UpdateItem returns null #336

Open bladerunner2020 opened 4 years ago

bladerunner2020 commented 4 years ago

Not sure if this is a bug or a feature ) I noticed that UpdateItem returns null instead of response. I looked at the source code and found that UpdateItem returns responses.__thisIndexer(0).ReturnedItem;. So null is the correct value, but such implementation doesn't allow to track possible Errors.

If there is an error in repose (ErrorCode !== 0) there is no way to track this.

I could use UpdateItems instead of UpdateItem - so it's not big deal. Still I think UpdateItem should return the whole response...

I think it should be:

   return responses.__thisIndexer(0); // .ReturnedItem should be removed
gautamsi commented 4 years ago

send me example code for evaluation. usually null means there was no error, otherwise errors will be thrown.

if you want to access updated item, just access the original item object which is re populated with server returned values.

bladerunner2020 commented 4 years ago

send me example code for evaluation. usually null means there was no error, otherwise errors will be thrown.

if you want to access updated item, just access the original item object which is re populated with server returned values.

In fact, null is Ok, if UpdateItem succeeds, but if it returns ErrorCode, the result will be lost and the answer will be null. Unfortunately, I don't know how to trigger error with UpdateItem, so I can't prove this ).

My code is:

const updateItem = ({ calendarId, uniqueId, changeKey }) => {
    const itemId = new ItemId(uniqueId);
    itemId.ChangeKey = changeKey; // Not required?

    Appointment.Bind(exch, itemId).done(meeting => {
        meeting.Subject = meeting.Subject + 'Extended by 1 hour';
        meeting.End = meeting.End.Add(15 * 60 * 1000, 'ms');

        const folderId = new FolderId(WellKnownFolderName.Calendar, new Mailbox(calendarId));

        // exch.UpdateItem(meeting, folderId, ConflictResolutionMode.AlwaysOverwrite, MessageDisposition.SaveOnly, SendInvitationsOrCancellationsMode.SendToNone)
        exch.UpdateItems([ meeting ], folderId, ConflictResolutionMode.AlwaysOverwrite, MessageDisposition.SaveOnly, SendInvitationsOrCancellationsMode.SendToNone)
            .catch(err => {
                console.log(err);
            })
            .then((data) => {
                if (data) {
                    const { Responses } = data;
                    console.log(Responses[0]);
                }
            });
    });
};

If I use UpdateItems, the answer I received is (it's ok):

BatchProcessingStopped:false
conflictCount:0
ConflictCount:0
errorCode:0
ErrorCode:0
errorDetails:DictionaryWithStringKey {keys: Array(0), keysToObjs: Object, objects: Object, …}
ErrorDetails:DictionaryWithStringKey
ErrorMessage:undefined
errorProperties:Array(0) []
ErrorProperties:Array(0)
item:Appointment {lockObject: Object, OnChange: Array(0), setService: , …}
result:0
Result:0
returnedItem:null
ReturnedItem:null

Here I have access to ErrorCode, ErrorMessage, etc. If I use UpdateItem it returns ReturnedItem, which is null, which is legit, but in case of an error, it will be lost.

I believe you should return not responses.__thisIndexer(0).ReturnedItem, but just responses.__thisIndexer(0)