/// <summary> /// Get the response from EBS webservice /// </summary> /// <param name="url">url where need to post data</param> /// <param name="content">data in jSon string format</param> /// <param name="lstHeaders">http header required to make request to EBS</param> /// <param name="Method">Type of request ..POST in this case</param> /// <returns>Response in jSon string</returns> public static string Get(string url, string content, string Method) { string strResponse = ""; try { using (var request = new WebServiceRequest(Method)) { request.Encoding = Encoding.UTF8; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); // request.Headers.Add("connection", "close"); if (content == "") { strResponse = request.DownloadString(url); } else { strResponse = request.UploadString(url, content); } } } catch (WebException w) { WorkspaceAddIn.InfoLog(w.Message); } catch (Exception e) { WorkspaceAddIn.InfoLog(e.Message); } return(strResponse); }
/// <summary> /// Get required details to build WebRequest /// </summary> public void GetDetails(IIncident incidentRecord, IRecordContext recordContext) { _incidentRecord = incidentRecord; //Get the VIN Number string[] vinDetails = RightNowConnectService.GetService().getBusInfo(_incidentRecord.ID); if (vinDetails != null) { _vin = vinDetails[0].Split('~')[0]; } //Get OOTB ORG ID _supplierID = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "supplier_from_webservice", _incidentRecord); if (_supplierID == String.Empty) { WorkspaceAddIn.InfoLog("Supplier ID is blank"); return; } else { //Get EBS ORG ID _supplierID = RightNowConnectService.GetService().GetEbsOrgID(Convert.ToInt32(_supplierID)); } _causalPartNumber = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "causal_part_nmbr", _incidentRecord); if (_causalPartNumber == String.Empty) { WorkspaceAddIn.InfoLog("Causal Part Number is blank"); return; } _odometerReading = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "odometer_reading", _incidentRecord); if (_odometerReading == String.Empty) { WorkspaceAddIn.InfoLog("Odometer Reading is blank"); return; } _failedDate = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "failure_date", _incidentRecord); if (_failedDate == String.Empty) { WorkspaceAddIn.InfoLog("Failed Date is blank"); return; } //If all required info is valid then form jSon request parameter var content = GetReqParam(); var jsonContent = WebServiceRequest.JsonSerialize(content); jsonContent = jsonContent.Replace("xmlns", "@xmlns"); //Call webservice string jsonResponse = WebServiceRequest.Get(_curlURL, jsonContent, "POST"); if (jsonResponse == "") { WorkspaceAddIn.InfoLog("Server didn't return any info"); } else { ExtractResponse(jsonResponse); } return; }
/// <summary> /// Method to perform warranty check for creating "WARRANTY" type work order using old BOM query. /// </summary> public void WarrantyCheck(IIncident incidentRecord) { _rnConnectService = RightNowConnectService.GetService(); _rnConnectService._incidentVINObjects.Clear();//Clear the _incidentVINObjects variable that holds all incident_vin record to be updated with response _incidentRecord = incidentRecord; //Get basic field that need to be pass in webservce call, //Null validation of these fields are handle by workspace rules _odometer = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "odometer_reading", _incidentRecord); _causalPart = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "causal_part_nmbr", _incidentRecord); string failureDateInSTring = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "failure_date", _incidentRecord); _failureDate = Convert.ToDateTime(failureDateInSTring).ToString("dd-MMM-yyyy"); string[] busInfo = _rnConnectService.getBusInfo(_incidentRecord.ID); if (busInfo != null && busInfo.Length > 0) { if (busInfo.Length > 1) { WorkspaceAddIn.InfoLog("It seems multi VIN are mapped with Reporting Incident, warrant type work order" + " works only for individual VIN"); return; } else { _vin = busInfo[0].Split('~')[0]; _srNum = busInfo[0].Split('~')[1]; _incVinID = Convert.ToInt32(busInfo[0].Split('~')[2]); //If all required info is valid then form jSon request parameter var content = GetWarrantyReqParam(); var jsonContent = WebServiceRequest.JsonSerialize(content); jsonContent = jsonContent.Replace("xmlns", "@xmlns"); //Call webservice string jsonResponse = WebServiceRequest.Get(_curlURL, jsonContent, "POST"); if (jsonResponse == "") { WorkspaceAddIn.InfoLog("Server didn't returned any info"); return; } else { ExtractResponse(jsonResponse); _rnConnectService.updateIncidentVinRecords(); } } } else { WorkspaceAddIn.InfoLog("No Bus info found, please map a bus to reporting Incident and then click check warranty button"); return; } return; }
/// <summary> /// This function does basic validation like if unordered parts beed added to reported Incident, if so then /// Call EBS parts order web-service to pass parts related info and store NF_SALES_ORDER no to each parts record /// </summary> /// <returns>string content that need to send to web-service</returns> public void OrderParts(IIncident incidentRecord) { //Get reported Incident Info int orderTypeId = Convert.ToInt32(RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "order_type", incidentRecord)); int billToId = Convert.ToInt32(RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "Bill_to_site", incidentRecord)); int shipToId = Convert.ToInt32(RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "Ship_to_site", incidentRecord)); string claimNum = incidentRecord.RefNo; string projectNum = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "project_number", incidentRecord); string retrofitNum = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "retrofit_number", incidentRecord); //Get EBS ID from OSvC OOTB ID string billToEbsID = _rnConnectService.GetEbsID(billToId); string shipToEbsID = _rnConnectService.GetEbsID(shipToId); string orgEbsID = _rnConnectService.GetBusOwnerEbsID(Convert.ToInt32(incidentRecord.OrgID)); string odrTypName = _rnConnectService.GetOrderTypeName(orderTypeId); //Get unordered Parts mapped to reported incident _partsInfo = _rnConnectService.GetPartsInfo(incidentRecord.ID); if (_partsInfo == null || _partsInfo.Length <= 0) { WorkspaceAddIn.InfoLog("No parts have beed added to order"); return; } else { //Frame parts order request param structure var content = GetPartsOdrReqParam(odrTypName, orgEbsID, shipToEbsID, billToEbsID, claimNum, projectNum, retrofitNum); if (content == null) { return; } else { //Convert object to jSon string var jsonContent = WebServiceRequest.JsonSerialize(content); jsonContent = jsonContent.Replace("xmlns", "@xmlns"); //Call web-service string jsonResponse = WebServiceRequest.Get(_curlURL, jsonContent, "POST"); if (jsonResponse == "") { WorkspaceAddIn.InfoLog("Server didn't returned any info"); return; } else { ExtractResponse(jsonResponse); _rnConnectService.updateIncidentVinRecords(); } } } }
/// <summary> /// Get required details to build WebRequest /// </summary> public void MultiVinWarrantyCheck(IIncident incidentRecord) { try { _rnConnectService = RightNowConnectService.GetService(); _incidentRecord = incidentRecord; string multiWarrantyConfigValue = _rnConnectService.GetConfigValue("CUSTOM_CFG_NEW_BOM_QUERY"); if (multiWarrantyConfigValue != null) { var s = new JavaScriptSerializer(); var configVerb = s.Deserialize <ConfigVerbs.RootObject>(multiWarrantyConfigValue); _curlURL = configVerb.URL; _headerURL = configVerb.xmlns; _xmlnsURL = configVerb.RESTHeader.xmlns; _respApplication = configVerb.RESTHeader.RespApplication; _responsibility = configVerb.RESTHeader.Responsibility; _securityGroup = configVerb.RESTHeader.SecurityGroup; _nLSLanguage = configVerb.RESTHeader.NLSLanguage; _orgID = configVerb.RESTHeader.Org_Id; } _rnConnectService._incidentVINObjects.Clear();//Clear the _incidentVINObjects variable that holds all incident_vin record to be updated with response _causalPart = RightNowConnectService.GetService().getFieldFromIncidentRecord("CO", "causal_part_nmbr", incidentRecord); string[] internalIncInfo = _rnConnectService.GetInternalIncident(incidentRecord.ID); if (internalIncInfo != null) { _allInternalincident = internalIncInfo.ToList(); } if (_allInternalincident.Count > 0) { var tasks = new Task[_allInternalincident.Count]; int ii = 0; foreach (string internalIncident in _allInternalincident) { tasks[ii++] = Task.Factory.StartNew(() => RequestPerSR(internalIncident)); } Task.WaitAll(tasks); _rnConnectService.updateIncidentVinRecords();//Once all task over, call batch job to update Incident_VIN record } } catch (Exception ex) { WorkspaceAddIn.InfoLog("Exeption in GetDetails: " + ex.Message); } }
/// <summary> /// Funtion to handle ebs webservice response /// </summary> /// <param name="respJson">response in jSON string</param> public void ExtractResponse(string jsonResp) { Dictionary <string, object> data = (Dictionary <string, object>)WebServiceRequest.JsonDeSerialize(jsonResp); Dictionary <string, object> outputParam = (Dictionary <string, object>)data["OutputParameters"]; Dictionary <string, object> returnTbl = (Dictionary <string, object>)outputParam["P_RETURN_TBL"]; Dictionary <string, object> returnTblItem = (Dictionary <string, object>)returnTbl["P_RETURN_TBL_ITEM"]; if (returnTblItem["HASERROR"].ToString() == "1") { WorkspaceAddIn.InfoLog(returnTblItem["DESCRIPTION"].ToString()); return; } else { _rnConnectService.UpdatePartsRecord(_partsInfo, returnTblItem["SALES_ORDER_NO"].ToString()); //WorkspaceAddIn.InfoLog("Order sent successfully"); } }
/// <summary> /// Build Request-Response /// </summary> /// <param name="internalIncident">Internal incident info in string separated by "~"</param> public void RequestPerSR(string internalIncident) { try { //Get VIN and Incident_VIN record ID from Internal incident string[] vinsOfInternalInc = _rnConnectService.GetVins(Convert.ToInt32(internalIncident.Split('~')[0])); if (vinsOfInternalInc != null) { List <VINREC> vinlist = new List <VINREC>(); foreach (string individualVIN in vinsOfInternalInc) { string VinNo = individualVIN.Split('~')[0];//get VIN # VINREC vinRecord = new VINREC { VIN = VinNo }; vinlist.Add(vinRecord); } //If all required info is valid then form jSon request parameter var content = GetMultiVinWarrantyReqParam(internalIncident.Split('~')[2], vinlist); var jsonContent = WebServiceRequest.JsonSerialize(content); jsonContent = jsonContent.Replace("xmlns", "@xmlns"); //Call webservice string jsonResponse = WebServiceRequest.Get(_curlURL, jsonContent, "POST"); if (jsonResponse == "") { WorkspaceAddIn.InfoLog("Server didn't returned any info"); return; } else { ExtractResponse(jsonResponse, vinsOfInternalInc); _rnConnectService.updateIncidentVinRecords(); } } } catch (Exception ex) { WorkspaceAddIn.InfoLog("Exception in WebRequest: " + ex.Message); } }
/// <summary> /// Funtion to form Parts Order Req Param Structure /// </summary> public RootObject GetPartsOdrReqParam(string orderTypeName, string bosOwnerOrgEbsID, string shipToEbsID, string billToEbsID, string claimNum, string projectNumber, string retrofitNumber) { List <OELineRec> OE_LINE_REC = new List <OELineRec>(); foreach (string partinfo in _partsInfo) { string[] info = partinfo.Split('~'); OELineRec oeLineRec = new OELineRec(); oeLineRec.ORDERED_ID = info[0]; if (info[1] == "" || info[1] == null) { WorkspaceAddIn.InfoLog("Part Number is missing for part id " + info[0]); return(null); } oeLineRec.ORDERED_ITEM = info[1]; if (info[2] == "" || info[2] == null) { WorkspaceAddIn.InfoLog("Part quantity is missing for part id " + info[0]); return(null); } oeLineRec.ORDERED_QUANTITY = info[2]; oeLineRec.SHIP_SET = info[4]; oeLineRec.SOURCE_TYPE = info[3]; OE_LINE_REC.Add(oeLineRec); } var content = new RootObject { CREATE_A_SALES_ORDER_Input = new CreateASalesOrderInput { @xmlns = _headerURL, RESTHeader = new RESTHeader { @xmlns = _xmlnsURL, Responsibility = _responsibility, RespApplication = _respApplication, SecurityGroup = _securityGroup, NLSLanguage = _nLSLanguage, Org_Id = _orgID }, InputParameters = new InputParameters { P_OE_HEADER_REC = new POeHeaderRec { ORDER_TYPE = orderTypeName, CUSTOMER_ID = bosOwnerOrgEbsID, SHIP_TO_ORG_ID = shipToEbsID, INVOICE_TO_ORG_ID = billToEbsID, CLAIM_NUMBER = claimNum, PROJECT_NUMBER = projectNumber, RETROFIT_NUMBER = retrofitNumber }, P_OE_LINE_TBL = new POeLineTbl { OE_LINE_REC = OE_LINE_REC } } } }; return(content); }
/// <summary> /// Funtion to handle ebs webservice response /// </summary> /// <param name="respJson">response in jSON string</param> public void ExtractResponse(string jsonResp) { //save webservice response // RightNowConnectService.GetService().setIncidentField("CO", "WebServiceResponse", jsonResp, _incidentRecord); Dictionary <string, string> incidentVinInfo = new Dictionary <string, string>(); Dictionary <string, object> singleOptionGroup; jsonResp = jsonResp.Replace("@xmlns:xsi", "@xmlns_xsi"); //formating json string jsonResp = jsonResp.Replace("@xsi:nil", "@xsi_nil"); //formating json string jsonResp = jsonResp.Replace("PKG_V2-24", "PKG_V2_24"); //formating json string //converting json string to Dictionary<string, object> Dictionary <string, object> data = (Dictionary <string, object>)WebServiceRequest.JsonDeSerialize(jsonResp); Dictionary <string, object> output = (Dictionary <string, object>)data["OutputParameters"]; Dictionary <string, object> param = (Dictionary <string, object>)output["CIN_BOM_QUERY_PKG_V2_24ISPARTWA"]; string combo = ""; string busModel = ""; string vin = ""; string[] ewrInfo; string[] busInfo = _rnConnectService.getBusInfoIV(_incVinID); //Check if multi option group is retured, if so then save jSon response if (IsArray(param["CIN_BOM_QUERY_PKG_V2_24ISPARTWA_ITEM"])) { object[] optionItems = (object[])param["CIN_BOM_QUERY_PKG_V2_24ISPARTWA_ITEM"]; if (optionItems.Length == 1)//if one elemnet in an array that mean too single option group { singleOptionGroup = (Dictionary <string, object>)optionItems[0]; } else { //Get part desc from first item, as it will same across all item of multioption grp Dictionary <string, object> firstItem = (Dictionary <string, object>)optionItems[0]; RightNowConnectService.GetService().setIncidentField("CO", "causal_part_desc", firstItem["PART_DESC"].ToString(), _incidentRecord); //Include the vendor id (org) and EWR_Xref_Id in multi option grp object[], so it can be used in other add-in logic foreach (object option in optionItems) { Dictionary <string, object> response = (Dictionary <string, object>)option; if (busInfo != null && busInfo.Length > 0) { vin = busInfo[0].Split('~')[0]; busModel = vin.Substring(4, 1); combo = busModel + "-" + response["OPTIONGROUP_SEQNO"].ToString().Trim(); ewrInfo = _rnConnectService.getEWRID(combo); if (ewrInfo != null && ewrInfo.Length > 0) { response.Add("EWR_Xref_Id", ewrInfo[0].Split('~')[0]);// add EWR_Xref_Id in response list for multi option grp } } } string optionGrpJson = WebServiceRequest.JsonSerialize(output["CIN_BOM_QUERY_PKG_V2_24ISPARTWA"]); _rnConnectService.addIncidentVINRecord(_incVinID, null, optionGrpJson); return; } } //If 1 item is retured then set individual field of incident_vin record else { singleOptionGroup = (Dictionary <string, object>)param["CIN_BOM_QUERY_PKG_V2_24ISPARTWA_ITEM"]; } if (singleOptionGroup != null) { RightNowConnectService.GetService().setIncidentField("CO", "causal_part_desc", singleOptionGroup["PART_DESC"].ToString(), _incidentRecord); if (singleOptionGroup["VENDOR_ID"].ToString().Trim() != "") { //Get OOTB ORG ID from EBS ORG ID string orgID = _rnConnectService.GetOrgID(Convert.ToInt32(singleOptionGroup["VENDOR_ID"].ToString())); //RightNowConnectService.GetService().setIncidentField("CO", "supplier_from_webservice", orgID, _incidentRecord); incidentVinInfo.Add("supplier_from_webservice", orgID); } if (singleOptionGroup["DESCRIPTION"].ToString().Trim() == "Warranty Start Date and Date From Plant are blank for the VIN") { WorkspaceAddIn.InfoLog(singleOptionGroup["DESCRIPTION"].ToString()); } incidentVinInfo.Add("under_warranty", singleOptionGroup["ISCOVERED"].ToString().Trim()); incidentVinInfo.Add("causal_part_nmbr_bom_pn", singleOptionGroup["PART_NUMBER"].ToString().Trim()); incidentVinInfo.Add("causal_part_desc_bom_pn", singleOptionGroup["DESCRIPTION"].ToString().Trim()); incidentVinInfo.Add("coverage_name", singleOptionGroup["COVERAGE_NAME"].ToString().Trim()); incidentVinInfo.Add("coverage_desc", singleOptionGroup["COVERAGE_DESC"].ToString().Trim()); incidentVinInfo.Add("optiongroup_seqno", singleOptionGroup["OPTIONGROUP_SEQNO"].ToString().Trim()); incidentVinInfo.Add("s_policy_name", singleOptionGroup["SPOLICY_NAME"].ToString().Trim()); incidentVinInfo.Add("s_policy_desc", singleOptionGroup["SPOLICY_DESC"].ToString().Trim()); //_rnConnectService.addIncidentVINRecord(_incVinID, "", "", singleOptionGroup["ISCOVERED"].ToString(), "", // singleOptionGroup["OPTIONGROUP_SEQNO"].ToString()); //Logic to update EWR_Xref_Id field if (busInfo != null && busInfo.Length > 0) { vin = busInfo[0].Split('~')[0]; if (vin != "") { busModel = vin.Substring(4, 1); combo = busModel + "-" + singleOptionGroup["OPTIONGROUP_SEQNO"].ToString().Trim(); ewrInfo = _rnConnectService.getEWRID(combo); if (ewrInfo != null && ewrInfo.Length > 0) { incidentVinInfo.Add("EWR_Xref_Id", ewrInfo[0].Split('~')[0]); } } } _rnConnectService.addIncidentVINRecord(_incVinID, incidentVinInfo, ""); } }
/// <summary> /// Function to Complete the Creation of Records as per selected VINs. /// </summary> public void CompleteBuildProcess() { //Get Unselected and Selected Vins foreach (DataGridViewRow _row in dataGridView1.Rows) { if (Convert.ToBoolean(_row.Cells["Select_CheckBox"].Value) == false) { _unSelectedIDs.Add(_row.Cells["Bus ID"].Value.ToString()); } if (Convert.ToBoolean(_row.Cells["Select_CheckBox"].Value) == true) { _selectedIDs.Add(_row.Cells["Bus ID"].Value.ToString()); } } try { #region Unselected Vins if (_unSelectedIDs != null && _unSelectedIDs.Count > 0) { List <int> deleteVins = new List <int>(); string[] splitvins; int n; if (_existingAffectedVins != null && _existingAffectedVins.Count > 0) { foreach (string uvin in _unSelectedIDs) { foreach (string evin in _existingAffectedVins) { splitvins = evin.Split('~'); foreach (string v in splitvins) { bool isNumeric = int.TryParse(v, out n); if (isNumeric) { int busId = Convert.ToInt32(v);// First element is bus id and second is Incident_VIN ID if (Convert.ToInt32(uvin) == busId) { // First element is bus id and second is Incident_VIN ID //deleteVins.Add(Convert.ToInt32(evin.Split('~')[1])); deleteVins.Add(Convert.ToInt32(v)); } } } } } if (deleteVins.Count > 0) { RightNowConnectService.GetService().DeleteIncidentVIN(deleteVins, _incidentRecord.ID); } } } #endregion #region Selected Vins if (_selectedIDs != null && _selectedIDs.Count > 0) { List <int> addVins = new List <int>(); for (int i = 0; i < _selectedIDs.Count; i++) { if (CheckIfVinExist(_selectedIDs[i]) == false) //to make sure duplicate records are not created { addVins.Add(Convert.ToInt32(_selectedIDs[i])); _existingAffectedVins.Add(_selectedIDs[i]); } } if (addVins.Count > 0) { //Get SR ID from any of selected VIN (as they all belong to same SR) string[] srInfos = RightNowConnectService.GetService().getSRID(addVins); List <int> vinsOfSameSR = new List <int>(); int oldSRID = -1; int internalIncID = -1; //Below logic is to handle is VIN belongs to different SR //We have to create unique Internal incident based on SR for (int i = 0; i < srInfos.Length; i++) { //If first case if (i == 0) { //Store SR oldSRID = Convert.ToInt32(srInfos[i].Split('~')[0]); //Get Internal Incident for first SR internalIncID = RightNowConnectService.GetService().CreateInternalIncident(_contactRecord.ID, oldSRID, _incidentRecord.ID, WorkspaceAddIn._onLoadFSARVal, (int)_contactRecord.OrgID, _incidentRecord); vinsOfSameSR.Add(Convert.ToInt32(srInfos[i].Split('~')[1])); } else { //Keep on adding VIN if SR is same for next VIN if (oldSRID == Convert.ToInt32(srInfos[i].Split('~')[0])) { vinsOfSameSR.Add(Convert.ToInt32(srInfos[i].Split('~')[1])); } //First save previously added VIN for prev SR, then clean the vinsOfSameSR list and repeat the process else { RightNowConnectService.GetService().createIncidentVIN(vinsOfSameSR, internalIncID); vinsOfSameSR.Clear(); oldSRID = Convert.ToInt32(srInfos[i].Split('~')[0]); internalIncID = RightNowConnectService.GetService().CreateInternalIncident(_contactRecord.ID, oldSRID, _incidentRecord.ID, WorkspaceAddIn._onLoadFSARVal, (int)_contactRecord.OrgID, _incidentRecord); vinsOfSameSR.Add(Convert.ToInt32(srInfos[i].Split('~')[1])); } } } RightNowConnectService.GetService().createIncidentVIN(addVins, internalIncID); } } #endregion if (this.IsHandleCreated) { this.BeginInvoke(new Action(() => { form.Hide(); })); } _buildCount++; MessageBox.Show(this, "Build Complete"); } catch (Exception ex) { if (this.IsHandleCreated) { this.BeginInvoke(new Action(() => { form.Hide(); })); } WorkspaceAddIn.InfoLog("Exception in Build Button Event: " + ex.Message); } }