Page 1 of 1

SY_WebhookSubscription.ItemNo

PostPosted: Mon Aug 03, 2020 2:38 pm
by SBarnes
How is the value of SY_WebhookSubscription.ItemNo determined, because it looks like every row is getting the value of 1?

Re: SY_WebhookSubscription.ItemNo

PostPosted: Mon Aug 03, 2020 7:09 pm
by SBarnes
How does SY_WebhookSubscription.ItemNo also work?

Re: SY_WebhookSubscription.ItemNo

PostPosted: Tue Aug 04, 2020 11:59 am
by Mike.Sheen
The ItemNo of the SY_WebHookSubscription is set for you automatically when a POST is made to /Webhooks/Subscribers/{SubscriberID}/Subscriptions/

It uses the maximum item No of the existing SY_WebhookSubscription.ItemNo for the same Subscriber as you are creating the subscription for.

Code: Select all
Db.ExecuteSql(@"INSERT INTO SY_WebhookSubscription (RecID, SY_WebhookSubscriber_RecID, EventName, URL, ItemNo, LastSavedDateTime)
    VALUES (@RecID, @SY_WebhookSubscriber_RecID, @EventName, @URL, (SELECT COALESCE(MAX(ItemNo), 0) + 1 FROM SY_WebhookSubscription WHERE SY_WebhookSubscription.SY_WebhookSubscriber_RecID = @ItemNo_SY_WebhookSubscriber_RecID), SYSUTCDATETIME())",


So, if you were to look at a list of all the subscriptions for a particular subscriber id, you should have sequential item no's for the SY_WebhookSubscription records.

Re: SY_WebhookSubscription.ItemNo

PostPosted: Tue Aug 04, 2020 12:45 pm
by SBarnes
I hate to tell you but it doesn't do that see below, I had found the code you mentioned in the Rest api plugin and thought I was misreading the code somehow, this is by using swagger

webhooks.jpg

Re: SY_WebhookSubscription.ItemNo

PostPosted: Tue Aug 04, 2020 1:02 pm
by Scott.Pearce
Please log a bug.

Code: Select all
            Db.ExecuteSql(@"INSERT INTO SY_WebhookSubscription (RecID, SY_WebhookSubscriber_RecID, EventName, URL, ItemNo, LastSavedDateTime)
                                 VALUES (@RecID, @SY_WebhookSubscriber_RecID, @EventName, @URL, (SELECT COALESCE(MAX(ItemNo), 0) + 1 FROM SY_WebhookSubscription WHERE SY_WebhookSubscription.SY_WebhookSubscriber_RecID = @ItemNo_SY_WebhookSubscriber_RecID), SYSUTCDATETIME())",
                              new
                              {
                                  RecID = newSubscription.RecID,
                                  SY_WebhookSubscriber_RecID = newSubscription.SY_WebhookSubscriber_RecID,
                                  EventName = newSubscription.EventName,
                                  URL = newSubscription.URL,
                                  ItemNo_SY_WebhookSubscriber_RecID = newSubscription.RecID
                              });


I can see that ItemNo_SY_WebhookSubscriber_RecID is being set to newSubscription.RecID instead of newSubscription.SY_WebhookSubscriber_RecID.

Re: SY_WebhookSubscription.ItemNo

PostPosted: Tue Aug 04, 2020 1:24 pm
by SBarnes