/// <summary>
        /// Update PartsOrderInstruction object with number of vin completed currently
        /// </summary>
        /// <param name="numOfVIN"></param>
        /// <param name="partOdrInstrID"></param>
        public void UpdatePartsOrderInstruction(int numOfVIN, int partOdrInstrID)
        {
            try
            {
                int           completedQuantity = GetCompletedQty(partOdrInstrID);
                GenericObject genObject         = new GenericObject();
                genObject.ObjectType = new RNObjectType
                {
                    Namespace = "Other",
                    TypeName  = "PartOrderInstruction"
                };
                genObject.ID = new ID {
                    id = partOdrInstrID, idSpecified = true
                };

                List <GenericField> customFields = new List <GenericField>();
                customFields.Add(createGenericField("Completed_Quantity", createIntegerDataValue(numOfVIN + completedQuantity), DataTypeEnum.INTEGER));

                genObject.GenericFields = customFields.ToArray();

                ClientInfoHeader hdr = new ClientInfoHeader()
                {
                    AppID = "Update PartsOrderInstruction"
                };

                _rightNowClient.Update(hdr, new RNObject[] { genObject }, new UpdateProcessingOptions {
                    SuppressExternalEvents = false, SuppressRules = false
                });
            }
            catch (Exception ex)
            {
                ReportCommandAddIn.form.Hide();
                MessageBox.Show("Exception in updating PartsOrderInstruction Record: " + ex.Message);
            }
        }
Пример #2
0
        public void updateObject(RNObject[] objects)
        {
            //Create the update processiong options
            UpdateProcessingOptions options = new UpdateProcessingOptions();

            options.SuppressExternalEvents = false;
            options.SuppressRules          = false;


            //Invoke the Update operation
            _rnowClient.Update(this._rnowClientInfoHeader, objects, options);
        }
        internal GenericServiceResponse UpdateObjects(RNObject[] objects)
        {
            bool mustRetry  = false;    // used to determine if we should retry a failed job
            int  retryTimes = 0;        // we don't want to endlessly retry, so we only will retry 3 times

            do
            {
                try
                {
                    _client.Update(_clientInfoHeader, objects, new UpdateProcessingOptions {
                        SuppressExternalEvents = false, SuppressRules = false
                    });

                    return(new GenericServiceResponse()
                    {
                        Successful = true
                    });
                }
                catch (Exception ex)
                {
                    GlobalContext.Log(string.Format("Failed Update: Retry {0}: {1}", retryTimes, ex.Message), true);
                    GlobalContext.Log(string.Format("Failed Update: Retry {0}: {1}{2}{3}", retryTimes, ex.Message, Environment.NewLine, ex.StackTrace), false);

                    string innerExMsg = GetInnerExceptionMessage(ex);
                    if (!string.IsNullOrEmpty(innerExMsg))
                    {
                        GlobalContext.Log(string.Format("Failed Update: Retry {0}: InnerException Messages: {1}", retryTimes, innerExMsg), true);
                    }

                    if (retryTimes < 3)
                    {
                        // if we haven't retried 3 times then we retry the load again
                        mustRetry = true;
                        retryTimes++;
                    }
                    else
                    {
                        // don't retry for 3rd retry
                        return(new GenericServiceResponse()
                        {
                            SuccessfulSet = true,
                            Successful = false,
                            Details = ex.ToString()
                        });
                    }
                }
                GlobalContext.Log(string.Format("Update Must Retry {0}", mustRetry), false);
            } while (mustRetry);
            GlobalContext.Log("Update End: This code should never be hit.", false);
            return(null);        // this code should never be hit
        }
Пример #4
0
            /// <summary>
            /// Create a log entry in the custom object PSLog$Log
            ///
            /// If this table does not exists, please retrieve the package from: https://tools.src.rightnow.com/spaces/logging/documents
            /// </summary>
            /// <param name="client">Extend the RightNow soap client</param>
            /// <param name="existingID">ID of the existing PSLog object</param>
            /// <param name="type">Optional (default=blank): application type causing the log m
            /// <param name="message">Optional (default=blank): human readable friendly message</param>essage</param>
            /// <param name="subtype">Optional (default=blank): friendly name of the application</param>
            /// <param name="source">Optional (default=blank): name of the current assembly or script</param>
            /// <param name="note">Optional (default=blank): additional details about the message</param>
            /// <param name="interfaceID">Optional (default=blank): the interface this error occurred on. (GlobalContext.InterfaceId)</param>
            /// <param name="severity">Optional (default=blank): mark the importance of the message</param>
            /// <param name="exception">Optional (default=blank): if populated the stack trace from the exception will be stored in the log</param>
            /// <param name="account">Optional (default=blank): reference to an Account</param>
            /// <param name="answer">Optional (default=blank): reference to an Answer</param>
            /// <param name="contact">Optional (default=blank): reference to a Contact</param>
            /// <param name="incident">Optional (default=blank): reference to an Incident</param>
            /// <param name="opportunity">Optional (default=blank): reference to an Opportunity</param>
            /// <param name="org">Optional (default=blank): reference to an Organization</param>
            /// <param name="task">Optional (default=blank): reference to a Task</param>
            /// <param name="customObjects">Optional (default=blank): an array of custom object references. the name of the object must match the name of the database column</param>
            /// <returns>ID of the newly created log object</returns>
            public static void UpdateLog(this RightNowSyncPortClient client,
                                         int existingID,
                                         Type type                     = Type.None,
                                         string message                = null,
                                         string subtype                = null,
                                         string note                   = null,
                                         string source                 = null,
                                         int?interfaceID               = null,
                                         Severity severity             = Severity.None,
                                         Exception exception           = null,
                                         Account account               = null,
                                         Answer answer                 = null,
                                         Contact contact               = null,
                                         Incident incident             = null,
                                         Opportunity opportunity       = null,
                                         Organization org              = null,
                                         Task task                     = null,
                                         GenericObject[] customObjects = null)
            {
                try
                {
                    GenericObject go = CreateLogGenericObject(type, subtype, message, note, source, interfaceID, severity, exception, account, answer, contact, incident, opportunity, org, task, customObjects);
                    go.ID = new ID
                    {
                        id          = existingID,
                        idSpecified = true
                    };

                    client.Update(
                        new ClientInfoHeader {
                        AppID = "PSLog"
                    },
                        new RNObject[] { go },
                        new UpdateProcessingOptions {
                        SuppressExternalEvents = true, SuppressRules = false
                    });
                }
                catch (Exception ex)
                {
                    if (LogFailedEvent != null)
                    {
                        LogFailedEvent(ex);
                    }
                }
            }
        /// <summary>
        /// Create Internal Incident Records
        /// </summary>
        /// <param name="contactID"></param>
        /// <param name="srID"></param>
        /// <param name="reportingIncID"></param>
        /// <param name="fsarID"></param>
        /// <param name="orgID"></param>
        /// <returns></returns>
        public int CreateInternalIncident(int contactID, int srID, int reportingIncID, int fsarID, int orgID)
        {
            try
            {
                //Check if it exist in order to avoid duplicate record
                Incident internalIncident = new Incident();
                string   response         = checkIfInternalIncidentExistForSR(reportingIncID, srID);
                if (response != null)
                {
                    internalIncident.ID = new ID
                    {
                        id          = Convert.ToInt32(response),
                        idSpecified = true
                    };
                }
                /*Set OOTB fields*/
                IncidentContact primarycontact = new IncidentContact {
                    Contact = new NamedID {
                        ID = new ID {
                            id = contactID, idSpecified = true
                        }
                    }
                };
                internalIncident.PrimaryContact = primarycontact;
                internalIncident.Organization   = new NamedID {
                    ID = new ID {
                        id = orgID, idSpecified = true
                    }
                };

                /*Set Custom fields*/
                List <GenericField> customAttributes = new List <GenericField>();
                customAttributes.Add(createGenericField("FSAR", createNamedIDDataValue(fsarID), DataTypeEnum.NAMED_ID));
                customAttributes.Add(createGenericField("SalesRelease", createNamedIDDataValue(srID), DataTypeEnum.NAMED_ID));
                customAttributes.Add(createGenericField("reporting_incident", createNamedIDDataValue(reportingIncID), DataTypeEnum.NAMED_ID));
                GenericObject customAttributeobj = genericObject(customAttributes.ToArray(), "IncidentCustomFieldsc");
                GenericField  caPackage          = createGenericField("CO", createObjDataValue(customAttributeobj), DataTypeEnum.OBJECT);

                /*Set Custom fields*/
                List <GenericField> customFields = new List <GenericField>();
                customFields.Add(createGenericField("incident_type", createNamedIDDataValueForName("Internal Incident"), DataTypeEnum.NAMED_ID));//55 is id of "Internal incident"
                GenericObject customfieldobj = genericObject(customFields.ToArray(), "IncidentCustomFieldsc");
                GenericField  cfpackage      = createGenericField("c", createObjDataValue(customfieldobj), DataTypeEnum.OBJECT);

                internalIncident.CustomFields = genericObject(new[] { caPackage, cfpackage }, "IncidentCustomFields");

                ClientInfoHeader hdr = new ClientInfoHeader()
                {
                    AppID = "Create Internal Incident"
                };
                //Update if internal incident exist
                if (response != null)
                {
                    _rightNowClient.Update(hdr, new RNObject[] { internalIncident }, new UpdateProcessingOptions {
                        SuppressExternalEvents = false, SuppressRules = false
                    });
                    return(Convert.ToInt32(response));
                }
                else//create a new internal incident
                {
                    RNObject[] resultobj = _rightNowClient.Create(hdr, new RNObject[] { internalIncident }, new CreateProcessingOptions {
                        SuppressExternalEvents = false, SuppressRules = false
                    });
                    if (resultobj != null)
                    {
                        return(Convert.ToInt32(resultobj[0].ID.id));
                    }
                }
            }
            catch (Exception ex)
            {
                WorkspaceAddIn.InfoLog("Excpetion in creating internal incident: " + ex.Message);
            }
            return(0);
        }
Пример #6
0
        /// <summary>
        /// Updates the latest values of the custome fields into database.
        /// </summary>
        /// <param name="staffAccount"></param>
        /// <returns></returns>
        public bool updateCustomFields(StaffAccount staffAccount)
        {
            try
            {
                Debug("RightNowConnectService - updateCustomFields() - Entry");

                GenericField csFldOOOEnd   = null;
                GenericField csFldOOOStart = null;

                Account account   = new Account();
                ID      accountID = new ID();
                accountID.id          = OutOfOfficeClientAddIn.GlobalContext.AccountId;
                accountID.idSpecified = true;
                account.ID            = accountID;


                // Out of Office Flag
                DataValue dv = new DataValue();
                dv.Items            = new Object[] { staffAccount.OooFlag };
                dv.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.BooleanValue };

                GenericField csFldOOOFlag = new GenericField();
                csFldOOOFlag.name              = CustomField.OooFlag;
                csFldOOOFlag.dataType          = DataTypeEnum.BOOLEAN;
                csFldOOOFlag.dataTypeSpecified = true;
                csFldOOOFlag.DataValue         = dv;

                // Out of Office Start
                csFldOOOStart                   = new GenericField();
                csFldOOOStart.name              = CustomField.OooStart;
                csFldOOOStart.dataType          = DataTypeEnum.DATETIME;
                csFldOOOStart.dataTypeSpecified = true;
                DataValue dvOooStart = null;
                if (staffAccount.OooStart != null && staffAccount.OooStart != default(DateTime))
                {
                    dvOooStart                  = new DataValue();
                    dvOooStart.Items            = new Object[] { staffAccount.OooStart };
                    dvOooStart.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue };
                }
                csFldOOOStart.DataValue = dvOooStart;

                // Out of Office End
                csFldOOOEnd                   = new GenericField();
                csFldOOOEnd.name              = CustomField.OooEnd;
                csFldOOOEnd.dataType          = DataTypeEnum.DATETIME;
                csFldOOOEnd.dataTypeSpecified = true;
                DataValue dvOooEnd = null;
                if (staffAccount.OooEnd != null)
                {
                    dvOooEnd                  = new DataValue();
                    dvOooEnd.Items            = new Object[] { staffAccount.OooEnd };
                    dvOooEnd.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue };
                }
                csFldOOOEnd.DataValue = dvOooEnd;

                // Out of Office Message Option
                DataValue dvOooMsgOption = new DataValue();
                dvOooMsgOption.Items            = new Object[] { staffAccount.OooMsgOption };
                dvOooMsgOption.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };

                GenericField csFldOOOMsgOption = new GenericField();
                csFldOOOMsgOption.name              = CustomField.OooMsgOption;
                csFldOOOMsgOption.dataType          = DataTypeEnum.STRING;
                csFldOOOMsgOption.dataTypeSpecified = true;
                csFldOOOMsgOption.DataValue         = dvOooMsgOption;

                // Out of Office Message
                DataValue dvOooMsg = new DataValue();
                dvOooMsg.Items            = new Object[] { staffAccount.OooMsg };
                dvOooMsg.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };

                GenericField csFldOOOMsg = new GenericField();
                csFldOOOMsg.name              = CustomField.OooMsg;
                csFldOOOMsg.dataType          = DataTypeEnum.STRING;
                csFldOOOMsg.dataTypeSpecified = true;
                csFldOOOMsg.DataValue         = dvOooMsg;

                // Out of Office Timezone
                GenericField csFldOOOTimezone = new GenericField();
                csFldOOOTimezone.name              = CustomField.OooTimezone;
                csFldOOOTimezone.dataType          = DataTypeEnum.STRING;
                csFldOOOTimezone.dataTypeSpecified = true;
                DataValue dvOooTimezone = null;
                if (null != staffAccount.OooTimezone)
                {
                    dvOooTimezone                  = new DataValue();
                    dvOooTimezone.Items            = new Object[] { staffAccount.OooTimezone };
                    dvOooTimezone.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };
                }
                csFldOOOTimezone.DataValue = dvOooTimezone;


                GenericObject customFieldsc = new GenericObject();

                customFieldsc.GenericFields = new GenericField[] { csFldOOOFlag, csFldOOOStart, csFldOOOEnd, csFldOOOMsgOption, csFldOOOMsg, csFldOOOTimezone };

                customFieldsc.ObjectType = new RNObjectType()
                {
                    TypeName = CustomField.AccountCustomFieldCollectionTypeName
                };

                GenericField customFieldsPackage = new GenericField();
                customFieldsPackage.name                       = "c";
                customFieldsPackage.dataType                   = DataTypeEnum.OBJECT;
                customFieldsPackage.dataTypeSpecified          = true;
                customFieldsPackage.DataValue                  = new DataValue();
                customFieldsPackage.DataValue.Items            = new[] { customFieldsc };
                customFieldsPackage.DataValue.ItemsElementName = new[] { ItemsChoiceType.ObjectValue };

                account.CustomFields = new GenericObject
                {
                    GenericFields = new[] { customFieldsPackage },
                    ObjectType    = new RNObjectType {
                        TypeName = CustomField.AccountCustomFieldsTypeName
                    }
                };

                ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                clientInfoHeader.AppID = OracleRightNowOOOAddInNames.OutOfOfficeAddIn;

                RNObject[] contactObjects = new RNObject[] { account };
                UpdateProcessingOptions updateProcessingOptions = new UpdateProcessingOptions();
                _rightNowClient.Update(clientInfoHeader, contactObjects, updateProcessingOptions);

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(OOOExceptionMessages.UnexpectedError, Common.Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Error(e.Message, e.StackTrace);
            }

            Debug("RightNowConnectService - updateCustomFields() - Exit");
            return(false);
        }
Пример #7
0
        static void GetAllContacts(RightNowSyncPortClient client)
        {
            Contact contactTemplate = new Contact();

            contactTemplate.Phones = new Phone[] { };

            UpdateProcessingOptions options = new UpdateProcessingOptions();

            RNObject[] objectTemplates = new RNObject[] { contactTemplate };
            bool       hasMoreResults  = true;

            int currentOffset = 0;

            do
            {
                var resultTable = client.QueryObjects(s_clientInfoHeader, String.Format("SELECT Contact FROM Contact LIMIT {0} OFFSET {1}", PageSize, currentOffset), objectTemplates, PageSize);

                RNObject[] rnObjects = resultTable[0].RNObjectsResult;

                List <RNObject> updatedObjects = new List <RNObject>();

                foreach (RNObject obj in rnObjects)
                {
                    Contact contact = (Contact)obj;
                    Phone[] phones  = contact.Phones;
                    if (phones != null)
                    {
                        List <Phone> newPhoneNumbers = new List <Phone>();

                        foreach (Phone phone in phones)
                        {
                            var sanitizedNumber = SanitizeNumber(phone.Number);

                            System.Console.WriteLine(contact.Name.Last + " - " + phone.Number + " (" + phone.RawNumber + ") - " + sanitizedNumber);
                            if (sanitizedNumber != phone.Number)
                            {
                                //need to create a new Phone object, if we reuse/update the existing one, the update won't work.
                                var newNumber = new Phone()
                                {
                                    action          = ActionEnum.update,
                                    actionSpecified = true,
                                    Number          = SanitizeNumber(phone.Number),
                                    PhoneType       = phone.PhoneType
                                };
                                newPhoneNumbers.Add(newNumber);
                            }
                        }
                        if (newPhoneNumbers.Count > 0)
                        {
                            updatedObjects.Add(new Contact()
                            {
                                ID     = contact.ID,
                                Phones = newPhoneNumbers.ToArray(),
                            });
                        }
                    }
                }

                if (updatedObjects.Count > 0)
                {
                    client.Update(s_clientInfoHeader, updatedObjects.ToArray(), options);
                }

                hasMoreResults = resultTable[0].Paging.ReturnedCount == PageSize;
                currentOffset  = currentOffset + resultTable[0].Paging.ReturnedCount;

                Console.WriteLine(String.Format("Processed {0} contacts", currentOffset));
            } while (hasMoreResults);
        }