Advertisement
crexin

Verify and update CRM WRPCTokenKey

Feb 22nd, 2023
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.37 KB | None | 0 0
  1. DECLARE @MostRecentKeyId uniqueidentifier
  2. DECLARE @CurrentActiveKeyId uniqueidentifier
  3.  
  4.  
  5. --Get most recent CrmWRPCTokenKey
  6.  
  7. SET @MostRecentKeyId =
  8. (SELECT top 1 id FROM CrmKey
  9. WHERE KeyType = 'CrmWRPCTokenKey'
  10. ORDER BY CreatedOn DESC)
  11.  
  12. --Get the current ActiveKeyId
  13.  
  14. SET @CurrentActiveKeyId =
  15. (SELECT ActiveKeyId FROM CrmKeySetting
  16. WHERE
  17. ActiveKeyId <> '00000000-0000-0000-0000-000000000000'
  18. AND KeyType = 'CrmWRPCTokenKey'
  19. AND IsConfigurationRow = 0)
  20.  
  21. --Make sure the most recent CrmWRPCTokenKey = current ActiveKeyId
  22.  
  23. IF @CurrentActiveKeyId <> @MostRecentKeyId
  24. BEGIN
  25. UPDATE CrmKeySetting
  26. SET ActiveKeyId = @MostRecentKeyId
  27. WHERE KeyType = 'CrmWRPCTokenKey'
  28. AND IsConfigurationRow = 0
  29. END
  30. ------------------------------------------------------------
  31. --Get most recent CrmTicketKey
  32.  
  33. SET @MostRecentKeyId =
  34. (SELECT top 1 id FROM CrmKey
  35. WHERE KeyType = 'CrmTicketKey'
  36. ORDER BY CreatedOn DESC)
  37.  
  38. --Get the current ActiveKeyId
  39.  
  40. SET @CurrentActiveKeyId =
  41. (SELECT ActiveKeyId FROM CrmKeySetting
  42. WHERE
  43. ActiveKeyId <> '00000000-0000-0000-0000-000000000000'
  44. AND KeyType = 'CrmTicketKey'
  45. AND IsConfigurationRow = 0)
  46.  
  47. --Make sure the most recent CrmTicketKey = current ActiveKeyId
  48.  
  49. IF @CurrentActiveKeyId <> @MostRecentKeyId
  50. BEGIN
  51. UPDATE CrmKeySetting
  52. SET ActiveKeyId = @MostRecentKeyId
  53. WHERE KeyType = 'CrmTicketKey'
  54. AND IsConfigurationRow = 0
  55. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement