internal static AnalyticsReportFilter GetStringAnalyticsReportFilter(string Name, String searchPhrase, int searchOperator, bool specifyAttributes, bool specifyDatatype, bool specifyOperator) { //Assigning the filter as defined on the RightNow Analytics Report AnalyticsReportFilter filter = new AnalyticsReportFilter(); if (specifyAttributes) { AnalyticsReportFilterAttributes attribute = new AnalyticsReportFilterAttributes(); attribute.Editable = false; attribute.Required = false; filter.Attributes = attribute; } if (specifyDatatype) { NamedID datatype = new NamedID(); datatype.Name = Name.GetType().ToString(); filter.DataType = datatype; } filter.Name = Name; if (specifyOperator) { filter.Operator = new NamedID { ID = new ID { id = searchOperator, idSpecified = true } } } ; filter.Values = new String[] { searchPhrase }; return(filter); }
internal RunAnalyticsResponse GetAnalyticsReportResults(long reportId, int limit = 100, int start = 0, string delimiter = ",") { //Create a filter and specify the filter name //Assigning the filter created in desktop agent to the new analytics filter AnalyticsReportFilter filter = new AnalyticsReportFilter(); //Apply the filter to the AnalyticsReport object return(GetAnalyticsReportResults(reportId, new AnalyticsReportFilter[] { filter }, limit, start, delimiter)); }
public AnalyticsReport getAnalyticsReport(long reportID) { AnalyticsReport analyticsReport = new AnalyticsReport(); ID analyticsReportID = new ID(); analyticsReportID.id = reportID; analyticsReportID.idSpecified = true; analyticsReport.ID = analyticsReportID; AnalyticsReportFilter filter = new AnalyticsReportFilter(); analyticsReport.Filters = (new AnalyticsReportFilter[] { filter }); GetProcessingOptions processingOptions = new GetProcessingOptions(); processingOptions.FetchAllNames = true; RNObject[] getAnalyticsObjects = new RNObject[] { analyticsReport }; RNObject[] rnObjects = _client.Get(_clientInfoHeader, getAnalyticsObjects, processingOptions); AnalyticsReport report = (AnalyticsReport)rnObjects[0]; return(report); }
internal static AnalyticsReportFilter GetDateTimeRangeAnalyticsReportFilter(string Name, DateTime fromDateTime, DateTime toDateTime, bool specifyAttributes, bool specifyDatatype, bool specifyOperator, bool appendEndingZ) { //Assigning the filter as defined on the RightNow Analytics Report AnalyticsReportFilter filter = new AnalyticsReportFilter(); if (specifyAttributes) { AnalyticsReportFilterAttributes attribute = new AnalyticsReportFilterAttributes(); attribute.Editable = false; attribute.Required = false; filter.Attributes = attribute; } if (specifyDatatype) { NamedID datatype = new NamedID(); datatype.Name = "Date Time"; filter.DataType = datatype; } filter.Name = Name; if (fromDateTime > DateTime.MinValue && toDateTime > DateTime.MinValue) { if (specifyDatatype) { filter.Operator = new NamedID { ID = new ID { id = ANALYTICS_FILTER_RANGE, idSpecified = true } } } ; if (appendEndingZ) { filter.Values = new[] { fromDateTime.ToString("s") + "Z", toDateTime.ToString("s") + "Z" } } ; else { filter.Values = new[] { fromDateTime.ToString("s"), toDateTime.ToString("s") } }; } else { if (fromDateTime > DateTime.MinValue) { if (specifyDatatype) { filter.Operator = new NamedID { ID = new ID { id = ANALYTICS_FILTER_GREATER_THAN_OR_EQUAL, idSpecified = true } } } ; if (appendEndingZ) { filter.Values = new[] { fromDateTime.ToString("s") + "Z" } } ; else { filter.Values = new[] { fromDateTime.ToString("s") } }; } else if (toDateTime > DateTime.MinValue) { if (specifyDatatype) { filter.Operator = new NamedID { ID = new ID { id = ANALYTICS_FILTER_LESS_THAN_OR_EQUAL, idSpecified = true } } } ; if (appendEndingZ) { filter.Values = new[] { toDateTime.ToString("s") + "Z" } } ; else { filter.Values = new[] { toDateTime.ToString("s") } }; } } return(filter); }
/* this method is called from framework to show the report row (data) * It combines the incident report (ConfigurationSetting.incidentsByContactReportID) * and the ServiceRequest.LookupSRbyContactPartyID(contactPartyID) * Currently this list is only showing certain fields (because of combining 2 lists with common fields) * The Right Now incidents by a contact report is hidden, meaning the Report control of a contact * workspace tab is based on the EBS Service Request List Table report definition * Also, do not change the default column heading of Right Now incidents by a contact report * (they are hard coded to uppercase). Because they are hidden anyway. * The EBS Service Request List Table report definition column headings can be changed and those are * the ones being displayed. */ public override IList <IReportRow> GetRows(IList <string> columns, IReportFilterNode filterNode) { IList <IReportRow> reportRows = new List <IReportRow>(); IRecordContext _context = ((EBSVirtualReportTablesPackage)this.Parent)._globalContext.AutomationContext.CurrentWorkspace; if (_context == null) { return(reportRows); } IContact contactRecord = _context.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact; /* report framework refresh every 30 sec (default) even though the tab is not active * so need to check contactRecord for null (when the editor is different) */ if (contactRecord == null) { return(reportRows); } int contactPartyID = 0; // get the ebs contact party custom attribute on the contact workspace contactPartyID = getContactPartyIdCustomAttr(contactRecord); // following to get the rNow incidents report and filter is the rNow contactID AnalyticsReport reportIncident = new AnalyticsReport(); ID rId = new ID(); rId.id = ConfigurationSetting.incidentsByContactReportID; rId.idSpecified = true; reportIncident.ID = rId; byte[] outByte = new byte[1000]; AnalyticsReportFilter[] filter = new AnalyticsReportFilter[3]; filter[0] = new AnalyticsReportFilter(); String[] filterString = new String[1]; filterString[0] = "" + contactRecord.ID; filter[0].Values = filterString; filter[0].Name = "Contact"; // incidents by a contact, thus Contact filter NamedID datatype = new NamedID(); datatype.Name = "Integer"; filter[0].DataType = datatype; reportIncident.Filters = filter; ClientInfoHeader _cih = new ClientInfoHeader(); _cih.AppID = "Accelerator Report Add-In"; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); CSVTableSet tableSet = ConfigurationSetting.client.RunAnalyticsReport( _cih, reportIncident, 100, 0, "\t", false, false, out outByte ); stopwatch.Stop(); string logMessage = "Called RightNowSyncPortClient.RunAnalyticsReport." + "reportID: " + ConfigurationSetting.incidentsByContactReportID; ConfigurationSetting.logWrap.DebugLog(0, contactRecord.ID, logMessage: logMessage, timeElapsed: (int)stopwatch.ElapsedMilliseconds); CSVTable[] csvTables = tableSet.CSVTables; CSVTable table = csvTables[0]; string[] rowData = table.Rows; int rNowIncidentCount = table.Rows.Length; int srVirtualTableCount = this.Columns.Count; string[] colHeadingIncidentReport = table.Columns.Split('\t'); foreach (String commaRow in table.Rows) { ReportDataRow reportDataRow = new ReportDataRow(srVirtualTableCount); string[] colValue = commaRow.Split('\t'); // the report output is stored as <columnHeading, value> Dictionary <string, string> dictRow = new Dictionary <string, string>(); int i = 0; foreach (string val in colValue) { /* make the column heading upper case (because the custom attribute heading * in the report designer sometime all in lower case, sometime the reverse) */ dictRow.Add(colHeadingIncidentReport[i].ToUpper(), val); i++; } addRnowIncidentRow(ref columns, ref reportDataRow, ref reportRows, dictRow); } if (contactPartyID > 0) { ServiceRequest[] sRs = ServiceRequest.LookupSRbyContactPartyID(contactPartyID, 0, contactRecord.ID); foreach (ServiceRequest req in sRs) { ReportDataRow reportDataRow = new ReportDataRow(this.Columns.Count); if (req != null) // live ebs row 316 of 319 of contact 4431 return null { addEBSsrRow(ref columns, ref reportDataRow, ref reportRows, req); } } } return(reportRows); }
/* this method is called from framework to show the report row (data) * refer to QA 140910-000144 for the story * It combines the incident report (ConfigurationSetting.incidentsByContactReportID) * and the ServiceRequest.LookupSRbyContactPartyID(contactPartyID) * Currently this list is only showing certain fields (because of combining 2 lists with common fields) * The Right Now incidents by a contact report is hidden, meaning the Report control of a contact * workspace tab is based on the Siebel Service Request List Table report definition * Also, do not change the default column heading of Right Now incidents by a contact report * (they are hard coded to uppercase). Because they are hidden anyway. * The Siebel Service Request List Table report definition column headings can be changed and those are * the ones being displayed. */ public override IList<IReportRow> GetRows(IList<string> columns, IReportFilterNode filterNode) { IList<IReportRow> reportRows = new List<IReportRow>(); IRecordContext _context = ((SiebelVirtualReportTablesPackage)this.Parent)._globalContext.AutomationContext.CurrentWorkspace; if (_context == null) return reportRows; IContact contactRecord = _context.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact; /* if auto refresh every x sec is enabled even though the tab is not active * so need to check contactRecord for null (when the editor is different) */ if (contactRecord == null) return reportRows; string contactPartyID = null; // get the ebs contact party custom attribute on the contact workspace contactPartyID = getContactPartyIdCustomAttr(contactRecord); // following to get the rNow incidents report and filter is the rNow contactID AnalyticsReport reportIncident = new AnalyticsReport(); ID rId = new ID(); rId.id = ConfigurationSetting.incidentsByContactReportID; rId.idSpecified = true; reportIncident.ID = rId; byte[] outByte = new byte[1000]; AnalyticsReportFilter[] filter = new AnalyticsReportFilter[3]; filter[0] = new AnalyticsReportFilter(); String[] filterString = new String[1]; filterString[0] = "" + contactRecord.ID; filter[0].Values = filterString; filter[0].Name = "Contact"; // incidents by a contact, thus Contact filter NamedID datatype = new NamedID(); datatype.Name = "Integer"; filter[0].DataType = datatype; reportIncident.Filters = filter; ClientInfoHeader _cih = new ClientInfoHeader(); _cih.AppID = "Accelerator Report Add-In"; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); CSVTableSet tableSet = ConfigurationSetting.client.RunAnalyticsReport( _cih, reportIncident, 100, 0, "\t", false, false, out outByte ); stopwatch.Stop(); string logMessage = "Called RightNowSyncPortClient.RunAnalyticsReport." + "reportID: " + ConfigurationSetting.incidentsByContactReportID; ConfigurationSetting.logWrap.DebugLog(0, contactRecord.ID, logMessage: logMessage, timeElapsed: (int)stopwatch.ElapsedMilliseconds); CSVTable[] csvTables = tableSet.CSVTables; CSVTable table = csvTables[0]; string[] rowData = table.Rows; int rNowIncidentCount = table.Rows.Length; int srVirtualTableCount = this.Columns.Count; string[] colHeadingIncidentReport = table.Columns.Split('\t'); foreach (String commaRow in table.Rows) { ReportDataRow reportDataRow = new ReportDataRow(srVirtualTableCount); string[] colValue = commaRow.Split('\t'); // the report output is stored as <columnHeading, value> Dictionary<string, string> dictRow = new Dictionary<string, string>(); int i = 0; foreach (string val in colValue) { /* make the column heading upper case (because the custom attribute heading * in the report designer sometime all in lower case, sometime the reverse) */ dictRow.Add(colHeadingIncidentReport[i].ToUpper(), val); i++; } addRnowIncidentRow(ref columns, ref reportDataRow, ref reportRows, dictRow); } if (contactPartyID != null) { ServiceRequest[] sRs = ServiceRequest.LookupSRbyContactPartyID(columns, contactPartyID, 0, contactRecord.ID); if (sRs == null) return reportRows; foreach (ServiceRequest req in sRs) { ReportDataRow reportDataRow = new ReportDataRow(this.Columns.Count); if (req != null) // live ebs row 316 of 319 of contact 4431 return null addSiebelSrRow(ref columns, ref reportDataRow, ref reportRows, req); } } return reportRows; }
// Check whether selected EBS Contact has associated to a RightNow Contact - using search report (via SOAP API) private String checkEBSContactPartyID(String contactPartyId, String email) { //Create a filter and specify the filter name //Assigning the filter created in desktop agent to the new analytics filter List<AnalyticsReportFilter> filterList = new List<AnalyticsReportFilter>(); if (contactPartyId != null) { AnalyticsReportFilter contactPartyIdFilter = new AnalyticsReportFilter(); contactPartyIdFilter.Name = "EBS Contact Party ID"; contactPartyIdFilter.Values = new String[] { contactPartyId }; filterList.Add(contactPartyIdFilter); } if (email != null) { AnalyticsReportFilter emailFilter = new AnalyticsReportFilter(); emailFilter.Name = "Email"; emailFilter.Values = new String[] { email }; filterList.Add(emailFilter); } String[] searchResults = null; // Get Report Search Result try{ searchResults = _rnSrv.getReportResult(_contactSearchReportId, filterList); } catch (Exception ex) { if (_log != null) { string logMessage = "Error in running contact search report via CWSS. Report ID = " + _contactSearchReportId + "; Error: " + ex.Message; string logNote = ""; _log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote); } MessageBox.Show("Error in checking selected contact. Please check log for detail. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return "0"; } // get associated id, if searched EBS Contact has been related to a RNow Contact String[] rowData = null; String associatedContactId = null; foreach (String row in searchResults) { rowData = row.Split(','); associatedContactId = rowData[0]; } return associatedContactId; }
private void bw_SearchRnContact(object sender, DoWorkEventArgs e) { string logMessage; string logNote; this.isSearchingRnContact = true; Dictionary<string, string> searchField = (Dictionary<string, string>)e.Argument; string email = searchField["email"]; string phoneDigits = searchField["phone"]; //Retireve RNow Contact Search Result //Check contact search report Id before running report if (_contactSearchReportId == 0) { logMessage = "Contact search report is not assigned in configuration."; logNote = ""; _log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote); e.Cancel = true; return; } logMessage = "Search contacts from CWSS. Search Report ID = " + _contactSearchReportId.ToString(); logNote = ""; _log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote); //Create a filter and specify the filter name //Assigning the filter created in desktop agent to the new analytics filter List<AnalyticsReportFilter> filterList = new List<AnalyticsReportFilter>(); /* * EBS Contact Search API does not support firstname/lastname search. * AnalyticsReportFilter lastNameFilter = new AnalyticsReportFilter(); lastNameFilter.Name = "Contact Last Name"; lastNameFilter.Values = new String[] { lastname }; filterList.Add(lastNameFilter); AnalyticsReportFilter firstNameFilter = new AnalyticsReportFilter(); firstNameFilter.Name = "Contact First Name"; firstNameFilter.Values = new String[] { firstname }; filterList.Add(firstNameFilter); */ AnalyticsReportFilter emailFilter = new AnalyticsReportFilter(); emailFilter.Name = "Email"; emailFilter.Values = new String[] { email }; filterList.Add(emailFilter); AnalyticsReportFilter phoneFilter = new AnalyticsReportFilter(); phoneFilter.Name = "Phone"; phoneFilter.Values = new String[] { phoneDigits }; filterList.Add(phoneFilter); String[] searchResults = null; try { searchResults = _rnSrv.getReportResult(_contactSearchReportId, filterList); } catch (Exception ex) { if (_log != null) { logMessage = "Error in searching Oracle Service Cloud contacts from CWSS. Error in running report: " + _contactSearchReportId + ": " + ex.Message; logNote = ""; _log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote); } MessageBox.Show("Exception in searching Oracle Service Cloud contacts via CWSS. Please check log for detail. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; return; } e.Result = searchResults; logMessage = "Report result is returned. Count = " + searchResults.Length; logNote = ""; _log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote); ; }
/// <summary> /// Generic helper method to create a lookup table /// This is used for performance reasons, so that main lookups all occur in memory instead of database lookups /// </summary> /// <param name="query"></param> /// <param name="limit"></param> /// <param name="useCache"></param> /// <returns></returns> public List <CSVTable> GetAnalyticsReport(long reportId, AnalyticsReportFilter[] filters, string delimiter = ",") { 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 if (filters == null) { filters = new AnalyticsReportFilter[] { }; } do { try { List <CSVTable> resultTableList = new List <CSVTable>(); int limit = 10000; long rowsReturned = Int64.MaxValue; long totalRowsReturned = 0; int offset = 0; while (rowsReturned >= limit) { var queryResult = GetAnalyticsReportResults(reportId, filters.ToArray(), limit, offset, delimiter); // "|"); if (!queryResult.Successful) { throw new Exception(queryResult.Details); } CSVTableSet thisset = queryResult.RunAnalyticsTableSet; foreach (CSVTable table in thisset.CSVTables) { resultTableList.Add(table); rowsReturned = table.Rows.Length; totalRowsReturned += rowsReturned; //break; } offset = offset + limit; } GlobalContext.Log(string.Format("GetAnalyticsReport Added {0} tables with a total of {1} records for ReportID {2}", resultTableList.Count, totalRowsReturned, reportId), false); return(resultTableList); } catch (Exception ex) { GlobalContext.Log(string.Format("GetAnalyticsReport Error calling ReportID {0}: Retry {1}: {2}\n{3}", reportId, retryTimes, ex.Message, ex.StackTrace), false); if (retryTimes < 4) { // if we haven't retried 4 times then we retry the load again mustRetry = true; retryTimes++; } else { throw ex; // don't retry for 4th retry } } GlobalContext.Log(string.Format("GetAnalyticsReport Must Retry {0}", mustRetry), false); } while (mustRetry); GlobalContext.Log("GetAnalyticsReport End: This code should never be hit.", false); return(null); // this code should never be hit }