166 lines
7.3 KiB
JavaScript
166 lines
7.3 KiB
JavaScript
import axios from "axios";
|
|
import https from 'https';
|
|
//import {XMLHttpRequest} from 'xmlhttprequest';
|
|
|
|
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0
|
|
|
|
|
|
const agent = new https.Agent({
|
|
rejectUnauthorized: false,
|
|
})
|
|
const crmHeaders = {
|
|
withCredentials: true,
|
|
headers:{
|
|
"Content-Type": "application/json; charset=utf-8",
|
|
"OData-MaxVersion": "4.0",
|
|
"OData-Version": "4.0",
|
|
"Accept": "application/json",
|
|
"Prefer": "odata.include-annotations=\"*\"",
|
|
agent
|
|
},
|
|
auth:{
|
|
username: 'xm\bondr',
|
|
password: '!Sky9fish1972'
|
|
}
|
|
}
|
|
|
|
|
|
export const getBasicSearch = (searchString) => {
|
|
console.log('got to axios', searchString)
|
|
|
|
return axios
|
|
//.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" + searchString + "')&$count=true", crmHeaders)
|
|
//.get("https://jsonplaceholder.typicode.com/todos/1",{proxy:{protocol: 'http',host:'lon3.sme.zscloud.net',port: 80}})
|
|
.get("https://localhost:3000/api/searchresults2",{httpsAgent: new https.Agent({rejectUnauthorized:false})})
|
|
.then((res)=>res.data)
|
|
.catch((error)=>{
|
|
console.log('thiserror',error)
|
|
})
|
|
}
|
|
|
|
export const getBasicSearch2 = (searchString) =>{
|
|
|
|
|
|
var req = new XMLHttpRequest();
|
|
req.open("GET", "https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '"+ searchString +"')&$count=true", true);
|
|
req.setRequestHeader("OData-MaxVersion", "4.0");
|
|
req.setRequestHeader("OData-Version", "4.0");
|
|
req.setRequestHeader("Accept", "application/json");
|
|
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
|
|
req.onreadystatechange = function() {
|
|
if (this.readyState === 4) {
|
|
req.onreadystatechange = null;
|
|
if (this.status === 200) {
|
|
var results = JSON.parse(this.response);
|
|
var recordCount = results["@odata.count"];
|
|
for (var i = 0; i < results.value.length; i++) {
|
|
var _accountid_value = results.value[i]["_accountid_value"];
|
|
var _accountid_value_formatted = results.value[i]["_accountid_value@OData.Community.Display.V1.FormattedValue"];
|
|
var _accountid_value_lookuplogicalname = results.value[i]["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
|
|
var _customerid_value = results.value[i]["_customerid_value"];
|
|
var _customerid_value_formatted = results.value[i]["_customerid_value@OData.Community.Display.V1.FormattedValue"];
|
|
var _customerid_value_lookuplogicalname = results.value[i]["_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
|
|
var pinswg_appealcasetype = results.value[i]["pinswg_appealcasetype"];
|
|
var pinswg_appealcasetype_formatted = results.value[i]["pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"];
|
|
var statuscode = results.value[i]["statuscode"];
|
|
var ticketnumber = results.value[i]["ticketnumber"];
|
|
var title = results.value[i]["title"];
|
|
}
|
|
} else {
|
|
console.log(this.statusText);
|
|
}
|
|
}
|
|
};
|
|
return (req.send());
|
|
|
|
}
|
|
|
|
//get list of entitydefinitions
|
|
//https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/EntityDefinitions?$select=LogicalName
|
|
|
|
// get list of appealtypes
|
|
//https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/stringmaps?$filter=attributename%20eq%20%27pinswg_appealcasetype%27&$count=true
|
|
|
|
//get crm xml form for appealtype
|
|
//https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/systemforms?$select=formid,name,formxml&$filter=(objecttypecode%20eq%20%27pinswg_dns%27and%20type%20eq%202)&$count=true
|
|
// then use regex to remove the escape
|
|
// convert xml to json and return
|
|
// promise example
|
|
// var xml2js = require('xml2js');
|
|
// var xml = '<foo></foo>';
|
|
|
|
// // With parser
|
|
// var parser = new xml2js.Parser(/* options */);
|
|
// parser.parseStringPromise(data).then(function (result) {
|
|
// console.dir(result);
|
|
// console.log('Done');
|
|
// })
|
|
// .catch(function (err) {
|
|
// // Failed
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
export const getAppealTypeDetail = (caseReference,appealcasetype) =>{
|
|
console.log('got to axios', searchString)
|
|
// example appealcasetype type pinswg_householderappealhases
|
|
return axios
|
|
.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/" + appealcasetype + "?$filter=pinswg_name eq '" + caseReference + "'",{httpsAgent: new https.Agent({rejectUnauthorized:false})})
|
|
.then((res)=>res.data)
|
|
.catch((error)=>{
|
|
console.log('thi serror',error)
|
|
})
|
|
|
|
}
|
|
//https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/pinswg_planningappeals78s?$filter=pinswg_name eq 'CAS-00015-L7J9H1'
|
|
|
|
export const getLPA = () =>{
|
|
console.log('got to axios', searchString)
|
|
|
|
return axios
|
|
.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/accounts?$select=name",{httpsAgent: new https.Agent({rejectUnauthorized:false})})
|
|
.then((res)=>res.data)
|
|
.catch((error)=>{
|
|
console.log('thi serror',error)
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// var req = new XMLHttpRequest();
|
|
// req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '000')&$count=true", true);
|
|
// req.setRequestHeader("OData-MaxVersion", "4.0");
|
|
// req.setRequestHeader("OData-Version", "4.0");
|
|
// req.setRequestHeader("Accept", "application/json");
|
|
// req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|
// req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
|
|
// req.onreadystatechange = function() {
|
|
// if (this.readyState === 4) {
|
|
// req.onreadystatechange = null;
|
|
// if (this.status === 200) {
|
|
// var results = JSON.parse(this.response);
|
|
// var recordCount = results["@odata.count"];
|
|
// for (var i = 0; i < results.value.length; i++) {
|
|
// var _accountid_value = results.value[i]["_accountid_value"];
|
|
// var _accountid_value_formatted = results.value[i]["_accountid_value@OData.Community.Display.V1.FormattedValue"];
|
|
// var _accountid_value_lookuplogicalname = results.value[i]["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
|
|
// var _customerid_value = results.value[i]["_customerid_value"];
|
|
// var _customerid_value_formatted = results.value[i]["_customerid_value@OData.Community.Display.V1.FormattedValue"];
|
|
// var _customerid_value_lookuplogicalname = results.value[i]["_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
|
|
// var pinswg_appealcasetype = results.value[i]["pinswg_appealcasetype"];
|
|
// var pinswg_appealcasetype_formatted = results.value[i]["pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"];
|
|
// var statuscode = results.value[i]["statuscode"];
|
|
// var ticketnumber = results.value[i]["ticketnumber"];
|
|
// var title = results.value[i]["title"];
|
|
// }
|
|
// } else {
|
|
// Xrm.Utility.alertDialog(this.statusText);
|
|
// }
|
|
// }
|
|
// };
|
|
// req.send();
|