/// <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> /// 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 handle ebs webservice response /// </summary> /// <param name="respJson">response in jSON string</param> public void ExtractResponse(string jsonResp) { int _internalIncidentID = 0; string[] internalIncident = RightNowConnectService.GetService().GetAllInternalIncident(_incidentRecord.ID); if (internalIncident != null) { _internalIncidentID = Convert.ToInt32(internalIncident[0]); } //Extract response Dictionary <string, object> data = (Dictionary <string, object>)WebServiceRequest.JsonDeSerialize(jsonResp); Dictionary <String, object> outputParameters = (Dictionary <String, object>)data["OutputParameters"]; Dictionary <String, object> output = (Dictionary <String, object>)outputParameters["CIN_SUPPLIER_WARRANTY_PKG-24ISP"]; if (output["ISCOVERED"].ToString() == "1") { //autogenerate sClaim //_rnConnectService.CreatesClaim(_incidentRecord.ID); RightNowConnectService.GetService().UpdateInternalIncidentForSupplier(_internalIncidentID, true, output["DESCRIPTION"].ToString()); //Create a child object to store Supplier recoverable limit _rnConnectService.CreateSupplierInfo(_incidentRecord.ID, output["DESCRIPTION"].ToString(), output["TEMPLATE_NAME"].ToString(), output["PARTS_REIMB_PERC"].ToString(), output["PARTS_MAX_AMOUNT"].ToString(), output["LABOUR_REIMB_PERC"].ToString(), output["LABOUR_MAX_AMOUNT"].ToString(), output["OTHER_REIMB_PERC"].ToString(), output["OTHER_MAX_AMOUNT"].ToString() ); } else { RightNowConnectService.GetService().UpdateInternalIncidentForSupplier(_internalIncidentID, false, output["DESCRIPTION"].ToString()); } }
/// <summary> /// Get the Incident Vin ID /// </summary> /// <param name="vinInfos"></param> /// <param name="vin"></param> /// <returns></returns> private void ExtractIncidentVinInfo(object vinItem, string[] vinsOfInternalInc) { Dictionary <string, object> singleOptionGroup = null; string orgID = ""; string vendorID = ""; Dictionary <string, object> item = (Dictionary <string, object>)vinItem; Dictionary <string, string> incidentVinInfo = new Dictionary <string, string>(); string combo = ""; string busModel = ""; string vin = ""; string[] ewrInfo; int incidentVinID = getIncidentVinID(vinsOfInternalInc, item["VIN"].ToString()); string[] busInfo = _rnConnectService.getBusInfoIV(incidentVinID); //By deafult set causal_part_desc at RI level RightNowConnectService.GetService().setIncidentField("CO", "causal_part_desc", item["PART_DESC"].ToString(), _incidentRecord); //Get OOTB ORG ID from EBS ORG ID if (item["VENDOR_ID"].ToString().Trim() != "") { vendorID = item["VENDOR_ID"].ToString(); orgID = _rnConnectService.GetOrgID(Convert.ToInt32(vendorID)); incidentVinInfo.Add("supplier_from_webservice", orgID); } Dictionary <string, object> vinSubResult = (Dictionary <string, object>)item["VIN_SUB_RESULT"]; if (vinSubResult == null)//if no info sent by EBS then return { return; } //Check if multi option group is retured, if so then save jSon response if (IsArray(vinSubResult["VIN_SUB_RESULT_ITEM"])) { object[] optionItems = (object[])vinSubResult["VIN_SUB_RESULT_ITEM"]; if (optionItems.Length == 1)//if one elemnet in an array that mean too single option group { singleOptionGroup = (Dictionary <string, object>)optionItems[0]; } else { //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 (object[])((Dictionary <string, object>)((Dictionary <string, object>)vinItem)["VIN_SUB_RESULT"])["VIN_SUB_RESULT_ITEM"]) { 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 } } response.Add("VENDOR_ID", vendorID);//add VENDOR_ID in response list } string optionGrpJson = WebServiceRequest.JsonSerialize(((Dictionary <string, object>)vinItem)["VIN_SUB_RESULT"]); _rnConnectService.addIncidentVINRecord(incidentVinID, null, optionGrpJson); } } //If not in array that means single option group else { singleOptionGroup = (Dictionary <String, object>)vinSubResult["VIN_SUB_RESULT_ITEM"]; } if (singleOptionGroup != null) { incidentVinInfo.Add("warranty_start_date", singleOptionGroup["WARRANTY_START_DATE"].ToString().Trim()); incidentVinInfo.Add("warranty_end_date", singleOptionGroup["WARRANTY_END_DATE"].ToString().Trim()); incidentVinInfo.Add("under_warranty", singleOptionGroup["ISCOVERED"].ToString().Trim()); incidentVinInfo.Add("optiongroup_seqno", singleOptionGroup["OPTIONGROUP_SEQNO"].ToString().Trim()); incidentVinInfo.Add("causal_part_desc_bom_pn", singleOptionGroup["DESCRIPTION"].ToString().Trim()); incidentVinInfo.Add("causal_part_nmbr_bom_pn", singleOptionGroup["PART_NUMBER"].ToString().Trim()); //Logic to update EWR_Xref_Id field if (busInfo != null && busInfo.Length > 0) { vin = busInfo[0].Split('~')[0]; 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(incidentVinID, incidentVinInfo, ""); } }
/// <summary> /// Funtion to handle ebs webservice response /// </summary> /// <param name="respJson">response in jSON string</param> public void ExtractResponse(string jsonResp, string[] vinsOfInternalInc) { //Extract response Dictionary <string, object> data = (Dictionary <string, object>)WebServiceRequest.JsonDeSerialize(jsonResp); Dictionary <String, object> outputParameters = (Dictionary <String, object>)data["OutputParameters"]; Dictionary <String, object> output = (Dictionary <String, object>)outputParameters["CIN_BOM_QUERY_PKG_V2-24GETVINWA"]; //loop over each vin response if (IsArray(output["CIN_BOM_QUERY_PKG_V2-24GETVINWA_ITEM"])) { foreach (object vinItem in (object[])output["CIN_BOM_QUERY_PKG_V2-24GETVINWA_ITEM"]) { ExtractIncidentVinInfo(vinItem, vinsOfInternalInc); } } else { ExtractIncidentVinInfo(output["CIN_BOM_QUERY_PKG_V2-24GETVINWA_ITEM"], vinsOfInternalInc); } }
/// <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, ""); } }