/// <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, "");
            }
        }
Beispiel #2
0
        /// <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, "");
            }
        }