Пример #1
0
 public static bool SetRelationship(eSetRelationshipValue info)
 {
     try
     {
         string strUserID = clsSuiteCRMHelper.GetUserId();
         if (strUserID == "")
         {
             SuiteCRMUserSession.Login();
         }
         object data = new
         {
             @session         = SuiteCRMUserSession.id,
             @module_name     = info.module1,
             @module_id       = info.module1_id,
             @link_field_name = info.module2,
             @related_ids     = new string[] { info.module2_id }
         };
         var _value = clsGlobals.GetResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", data);
         if (_value.Created == 0)
         {
             return(false);
         }
     }
     catch (System.Exception exception)
     {
         exception.Data.Clear();
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// The protocols for how link fields are named vary. Try this possibility,
        /// and log failures.
        /// </summary>
        /// <param name="relationship">The relationship to set.</param>
        /// <param name="linkFieldName">The link field name to try.</param>
        /// <returns>True if the relationship was created, else false.</returns>
        public static bool TrySetRelationship(eSetRelationshipValue info, string linkFieldName)
        {
            bool result;

            if (EnsureLoggedIn())
            {
                object data = new
                {
                    @session         = SuiteCRMUserSession.id,
                    @module_name     = info.module1,
                    @module_id       = info.module1_id,
                    @link_field_name = linkFieldName,
                    @related_ids     = new string[] { info.module2_id },
                    @name_value_list = new eNameValue[] { },
                    @delete          = info.delete
                };
                var _value = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", data);

                if (_value.Failed > 0)
                {
                    Log.Warn($"SuiteCrmHelper.SetRelationship: failed to set relationship using link field name '{linkFieldName}'");
                }

                result = (_value.Created != 0);
            }
            else
            {
                result = false;
            }

            return(result);
        }
Пример #3
0
 /// <summary>
 /// Sets a CRM relationship and returns boolean success. 'Unsafe' because most
 /// callers ignore the result. Call 'SetRelationship' instead, which throws an
 /// exception on failure.
 /// </summary>
 public static bool SetRelationshipUnsafe(eSetRelationshipValue info)
 {
     try
     {
         return(SetRelationship(info));
     }
     catch (System.Exception exception)
     {
         Log.Warn("SetRelationship exception" + exception.ToString());
         // Swallow exception(!)
         return(false);
     }
 }
Пример #4
0
        private void AddCurrentUserAsOwner(Outlook.AppointmentItem olItem, string meetingId)
        {
            LogItemAction(olItem, "AppointmentSyncing.AddItemFromOutlookToCrm, adding current user");

            eSetRelationshipValue info = new eSetRelationshipValue
            {
                module2    = AppointmentSyncing.CrmModule,
                module2_id = meetingId,
                module1    = "Users",
                module1_id = clsSuiteCRMHelper.GetUserId()
            };

            clsSuiteCRMHelper.SetRelationshipUnsafe(info);
        }
 /// <summary>
 /// If it was created in Outlook and doesn't exist in CRM,  (in which case it won't yet have a
 /// magic SShouldSync property) then we need to guarantee changes made in CRM are copied back
 /// by setting the Sync to Outlook checkbox in CRM.
 /// </summary>
 /// <param name="contactIdInCRM">The identifier of the contact in the CRM system</param>
 /// <param name="syncProperty">If non null, set the checkbox.</param>
 private static void EnsureSyncWithOutlookSetInCRM(string contactIdInCRM, Outlook.UserProperty syncProperty)
 {
     if (syncProperty == null)
     {
         eSetRelationshipValue info = new eSetRelationshipValue
         {
             module1    = CrmModule,
             module1_id = contactIdInCRM,
             module2    = "user_sync",
             module2_id = clsSuiteCRMHelper.GetUserId()
         };
         clsSuiteCRMHelper.SetRelationshipUnsafe(info);
     }
 }
Пример #6
0
        public static bool SetRelationship(eSetRelationshipValue info)
        {
            EnsureLoggedIn();
            object data = new
            {
                @session         = SuiteCRMUserSession.id,
                @module_name     = info.module1,
                @module_id       = info.module1_id,
                @link_field_name = info.module2,
                @related_ids     = new string[] { info.module2_id }
            };
            var _value = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", data);

            return(_value.Created != 0);
        }
Пример #7
0
        public bool createEmailRelationship(string emailId, TreeNode node)
        {
            eSetRelationshipValue info = new eSetRelationshipValue
            {
                module2    = "emails",
                module2_id = emailId,
                module1    = node.Parent.Text,
                module1_id = node.Tag.ToString()
            };

            if (!clsSuiteCRMHelper.SetRelationship(info))
            {
                return(false);
            }
            return(true);
        }
Пример #8
0
        /// <summary>
        /// Try, in turn, each field in this list of candidate fields seeking one which allows a relationship
        /// to be successfully created.
        /// </summary>
        /// <remarks>
        /// If the common relationship field names don't work, brute force it by getting all the possibles.
        /// </remarks>
        /// <param name="relationship">The relationship we're trying to make.</param>
        /// <param name="candidateFields">Fields through which the relationship might be made.</param>
        /// <returns>True if the relationship was made.</returns>
        private static bool TrySetRelationship(eSetRelationshipValue relationship, IEnumerable <eField> candidateFields)
        {
            bool result = false;

            foreach (eField field in candidateFields)
            {
                result |= TrySetRelationship(relationship, field.name.ToLower());

                if (result)
                {
                    break;
                }
            }

            return(result);
        }
Пример #9
0
        /// <summary>
        /// Sets up a CRM relationship to mimic an Outlook relationship
        /// </summary>
        /// <param name="_result"></param>
        /// <param name="objRecepient"></param>
        /// <param name="relnName"></param>
        /// <returns></returns>
        private string SetCrmRelationshipFromOutlook(string _result, Outlook.Recipient objRecepient, string relnName)
        {
            string sCID = GetID(objRecepient.Address, relnName);

            if (sCID != String.Empty)
            {
                eSetRelationshipValue info = new eSetRelationshipValue
                {
                    module2    = AppointmentSyncing.CrmModule,
                    module2_id = _result,
                    module1    = relnName,
                    module1_id = sCID
                };
                clsSuiteCRMHelper.SetRelationshipUnsafe(info);
            }

            return(sCID);
        }
        /// <summary>
        /// Sets up a CRM relationship to mimic an Outlook relationship
        /// </summary>
        /// <param name="meetingId">The ID of the meeting</param>
        /// <param name="foreignModule">the name of the module we're seeking to link with.</param>
        /// <returns>True if a relationship </returns>
        private bool SetCrmRelationshipFromOutlook(string meetingId, string foreignModule, string foreignId)
        {
            bool result = false;

            if (foreignId != String.Empty)
            {
                eSetRelationshipValue info = new eSetRelationshipValue
                {
                    module2    = AppointmentSyncing.CrmModule,
                    module2_id = meetingId,
                    module1    = foreignModule,
                    module1_id = foreignId
                };
                result = clsSuiteCRMHelper.SetRelationshipUnsafe(info);
            }

            return(result);
        }
Пример #11
0
        private void AddMeetingRecipientsFromOutlookToCrm(Outlook.AppointmentItem aItem, string meetingId)
        {
            LogItemAction(aItem, "AppointmentSyncing.AddMeetingRecipientsFromOutlookToCrm");
            foreach (Outlook.Recipient objRecepient in aItem.Recipients)
            {
                try
                {
                    Log.Info("objRecepientName= " + objRecepient.Name.ToString());
                    Log.Info("objRecepient= " + objRecepient.Address.ToString());
                }
                catch
                {
                    Log.Warn("objRecepient ERROR");
                    continue;
                }

                string sCID = SetCrmRelationshipFromOutlook(meetingId, objRecepient, ContactSyncing.CrmModule);
                if (sCID != String.Empty)
                {
                    string AccountID = clsSuiteCRMHelper.getRelationship(ContactSyncing.CrmModule, sCID, "accounts");

                    if (AccountID != String.Empty)
                    {
                        eSetRelationshipValue info = new eSetRelationshipValue
                        {
                            module2    = AppointmentSyncing.CrmModule,
                            module2_id = meetingId,
                            module1    = "Accounts",
                            module1_id = AccountID
                        };
                        clsSuiteCRMHelper.SetRelationshipUnsafe(info);
                    }
                    continue;
                }
                if (!String.IsNullOrEmpty(SetCrmRelationshipFromOutlook(meetingId, objRecepient, "Users")))
                {
                    continue;
                }
                if (!String.IsNullOrEmpty(SetCrmRelationshipFromOutlook(meetingId, objRecepient, "Leads")))
                {
                    continue;
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Sets a CRM relationship and returns boolean success. 'Unsafe' because most
        /// callers ignore the result. Call 'SetRelationship' instead, which throws an
        /// exception on failure.
        /// </summary>
        public static bool SetRelationshipUnsafe(eSetRelationshipValue info)
        {
            bool result;

            try
            {
                result = TrySetRelationship(info, Objective.Meeting);

                if (!result)
                {
                    Log.Warn("SuiteCrmHelper.SetRelationshipUnsafe: failed to set relationship");
                }
            }
            catch (System.Exception exception)
            {
                Log.Error("SuiteCrmHelper.SetRelationshipUnsafe:", exception);
                // Swallow exception(!)
                result = false;
            }

            return(result);
        }
Пример #13
0
 /// <summary>
 /// The protocols for how link fields are named vary. Try the most likely two possibilities,
 /// and log failures.
 /// </summary>
 /// <param name="relationship">The relationship to set.</param>
 /// <returns>True if the relationship was created, else false.</returns>
 public static bool TrySetRelationship(eSetRelationshipValue relationship, Objective objective)
 {
     return(TrySetRelationship(relationship, $"{relationship.module2}") ||
            TrySetRelationship(relationship, $"{relationship.module2}_{relationship.module1}") ||
            TrySetRelationship(relationship, GetActivitiesLinks(relationship.module1, objective)));
 }
 public static bool SetRelationship(eSetRelationshipValue info)
 {
     try
     {
         string strUserID = clsSuiteCRMHelper.GetUserId();
         if (strUserID == "")
         {
             SuiteCRMUserSession.Login();
         }
         object data = new
         {
             @session = SuiteCRMUserSession.id,
             @module_name = info.module1,
             @module_id = info.module1_id,
             @link_field_name = info.module2,
             @related_ids = new string[] { info.module2_id }
         };
         var _value = clsGlobals.GetResponse<RESTObjects.eNewSetRelationshipListResult>("set_relationship", data);
         if (_value.Created==0)
         {
             return false;
         }
     }
     catch (System.Exception exception)
     {
         exception.Data.Clear();
         return false;
     }
     return true;
 }