Allowing users to edit other activities via a Custom Form
Posted By: Alex.Cottner on June 7th, 2011 in General, Saleslogix
No Gravatar

The provided API to Edit, Complete, and Delete activities is as follows…
Application.BasicFunctions.EditActivity activityID
Application.BasicFunctions.CompleteActivity activityID
Application.BasicFunctions.DeleteActivity activityID

Unfortunately, there is a bug that adds the currently logged in user’s UserID to the end of the required query. This means that any time a user tries to edit another user’s activity, those API calls will fail. This happens even if they have full calendar access. This means we need to create some alternative solutions to the above API calls.Compensating for the delete method is easy, we can simply do…

doSQL "DELETE FROM ACTIVITY WHERE ACTIVITYID=" + ActivityID
doSQL "DELETE FROM USER_ACTIVITY WHERE ACTIVITYID=" + ActivityID
doSQL "DELETE FROM USERNOTIFICATION WHERE ACTIVITYID=" + ActivityID

A workaround for the Edit and Complete methods are a little more complicated. We’ll need to change the UserID field in the ACTIVITY and in the USER_ACTIVITY table. Then change it back once the user opens the Activity Details View (edit) or History Details View (complete) forms. We can do this with a Global. If you’re in an environment where a user should not be able to edit another users activities, then you will need to do a little extra work by looking at the UserCalendar table to first check if the user is allowed to access the calendar.

Dim strActID
strActID = dgActivities.GetCurrentField
Application.BasicFunctions.GlobalInfoSet "ActivityLeaderID", getField("USERID", "ACTIVITY", "ACTIVITYID=" + sqlQuote(strActID))
doSQL ("UPDATE ACTIVITY SET USERID=" + sqlQuote(Application.BasicFunctions.CurrentUserID) + " WHERE ACTIVITYID=" + sqlQuote(strActID))
doSQL ("UPDATE USER_ACTIVITY SET USERID=" + sqlQuote(Application.BasicFunctions.CurrentUserID) + " WHERE ACTIVITYID=" + sqlQuote(strActID))
Application.BasicFunctions.(Edit/Delete)Activity strActID

Now we have our Global set, we need to insert some code into our forms that will read it and clear this Global once they open.

Activity Details View - Added to AXFormShow
if (Application.BasicFunctions.GlobalInfoExists("ActivityLeaderID")) then
lveLeader.LookupID = Application.BasicFunctions.GlobalInfoFor("ActivityLeaderID")
lveLeader.Text = GetField("USERNAME", "USERINFO", "USERID=" + SqlQuote(lveLeader.LookupID))
Application.BasicFunctions.GlobalInfoClear("ActivityLeaderID")
doSQL ("UPDATE ACTIVITY SET USERID=" + sqlQuote(lveLeader.LookupID) + " WHERE ACTIVITYID=" + sqlQuote(txtActivityID.Text))
doSQL ("UPDATE USER_ACTIVITY SET USERID=" + sqlQuote(lveLeader.LookupID) + " WHERE ACTIVITYID=" + sqlQuote(txtActivityID.Text))
end if
History Details View - Added to AXFormShow
if (Application.BasicFunctions.GlobalInfoExists("ActivityLeaderID")) then
lveLeader.LookupID = Application.BasicFunctions.GlobalInfoFor("ActivityLeaderID")
lveLeader.Text = GetField("USERNAME", "USERINFO", "USERID=" + SqlQuote(lveLeader.LookupID))
Application.BasicFunctions.GlobalInfoClear("ActivityLeaderID")
doSQL ("UPDATE ACTIVITY SET USERID=" + sqlQuote(lveLeader.LookupID) + " WHERE ACTIVITYID=" + sqlQuote(Activity.Key))
doSQL ("UPDATE USER_ACTIVITY SET USERID=" + sqlQuote(lveLeader.LookupID) + " WHERE ACTIVITYID=" + sqlQuote(Activity.Key))
end if

Leave a Reply