Skip to content

Instantly share code, notes, and snippets.

@justyntemme
Created August 7, 2017 16:05
Show Gist options
  • Save justyntemme/3a2795d65c4d1b9eb0bd8a7b9830f918 to your computer and use it in GitHub Desktop.
Save justyntemme/3a2795d65c4d1b9eb0bd8a7b9830f918 to your computer and use it in GitHub Desktop.
jQuery('#field53610330_2').click(function() {
jQuery("#field54441009").val("8");//
jQuery.get("https://api.pipedrive.com/v1/organizations/" + jQuery("#field53423360").val() + "?api_token=REDACTED", function(resp){
console.log(resp.data.b34abe6f7c4765955a312fbb286d4f1d94199baf)
if (resp.data.b34abe6f7c4765955a312fbb286d4f1d94199baf == '') {
alert("Recreational License Number Missing!\nPlease enter the Recreational License number for the Organization into Pipedrive, then close and re-open this form.\nFor help, contact Lorenzo at 831.334.6363");
}
});
});
//medical
//field53610330_1
//pipedrive custom field val 7
jQuery('#field53610330_1').click(function() {
jQuery("#field54441009").val("7");
jQuery.get("https://api.pipedrive.com/v1/organizations/" + jQuery("#field53423360").val() + "?api_token=REDACTED", function(resp){
if (resp.data.e5d15581b08037dc6cbd12c2778f364a4202cabd == '') {
alert("Medical License Number Missing!\nPlease enter the Medical License number for the Organization into Pipedrive, then close and re-open this form.\nFor help, contact Lorenzo at 831.334.6363");
}
});
});
// On click of submit add product fields to deals
jQuery("#fsSubmitButton2721774").click(function() {
var invocation = new XMLHttpRequest();
//First Product will be sent by defualt; the next will be checkedif not equal to -----
jQuery.get("https://api.pipedrive.com/v1/products/find?term=" + jQuery("#field53412749").val() + "&currency=USD&start=0&api_token=REDACTED", function(resp){
callOtherDomain(resp.data[1].id);
});
var url = "https://api.pipedrive.com/v1/deals/" + pipedrive_deal_ID + "/products?api_token=REDACTED";
function callOtherDomain(firstProductID){
var firstProductData = `{
"id": "` + pipedrive_deal_ID + `",
"product_id": "` + firstProductID +`",
"item_price": "` + jQuery("#field53456315").val() + `",
"quantity": "` + jQuery("#field53412750").val() + `",
"discount_percentage": "` + jQuery("#field53455830").val().replace("%", "") + `",
"duration": "1"
}`
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/json');
//invocation.onreadystatechange = handler;
invocation.send(firstProductData)
}
}
//Check if second field type is not equal to default; if so update deal with second as well
if (jQuery("#field53456857").val() != '----'){
var secondinvocation = new XMLHttpRequest();
jQuery.get("https://api.pipedrive.com/v1/products/find?term=" + jQuery("#field53456857").val() + "&currency=USD&start=0&api_token=READACTED", function(resp){
secondcallOtherDomain(resp.data[1].id);
});
function secondcallOtherDomain(secondProductID){
var secondProductData = `{
"id": "` + pipedrive_deal_ID + `",
"product_id": "` + secondProductID +`",
"item_price": "` + jQuery("#field53456858").val() + `",
"quantity": "` + jQuery("#field53456859").val() + `",
"discount_percentage": "` + jQuery("#field53456861").val().replace("%", "") + `",
"duration": "1"
}`
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/json');
//invocation.onreadystatechange = handler;
invocation.send(secondProductData)
}
}
}
// Third Field check and send
if (jQuery("#field53456838").val() != '----'){
var thirdinvocation = new XMLHttpRequest();
jQuery.get("https://api.pipedrive.com/v1/products/find?term=" + jQuery("#field53456838").val() + "&currency=USD&start=0&api_token=READACTED", function(resp){
thirdcallOtherDomain(resp.data[1].id);
});
function thirdcallOtherDomain(thirdProductID){
var thirdProductData = `{
"id": "` + pipedrive_deal_ID + `",
"product_id": "` + thirdProductID +`",
"item_price": "` + jQuery("#field53456840").val() + `",
"quantity": "` + jQuery("#field53456841").val() + `",
"discount_percentage": "` + jQuery("#field53456843").val().replace("%", "") + `",
"duration": "1"
}`
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/json');
//invocation.onreadystatechange = handler;
invocation.send(thirdProductData)
}
}
}
//4th
if (jQuery("#field53456847").val() != '----'){
var fourthinvocation = new XMLHttpRequest();
jQuery.get("https://api.pipedrive.com/v1/products/find?term=" + jQuery("#field53456847").val() + "&currency=USD&start=0&api_token=READACTED", function(resp){
fourthcallOtherDomain(resp.data[1].id);
});
function fourthcallOtherDomain(fourthProductID){
var fourthProductData = `{
"id": "` + pipedrive_deal_ID + `",
"product_id": "` + fourthProductID +`",
"item_price": "` + jQuery("#field53456850").val() + `",
"quantity": "` + jQuery("#field53456851").val() + `",
"discount_percentage": "` + jQuery("#field53456853").val().replace("%", "") + `",
"duration": "1"
}`
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/json');
//invocation.onreadystatechange = handler;
invocation.send(fourthProductData)
}
}
}
//5th and final product id :)
if (jQuery("#field53456822").val() != '----'){
var fifthinvocation = new XMLHttpRequest();
jQuery.get("https://api.pipedrive.com/v1/products/find?term=" + jQuery("#field53456822").val() + "&currency=USD&start=0&api_token=REDACTED", function(resp){
fifthcallOtherDomain(resp.data[1].id);
});
function fithcallOtherDomain(fifthProductID){
var fifthProductData = `{
"id": "` + pipedrive_deal_ID + `",
"product_id": "` + fifthProductID +`",
"item_price": "` + jQuery("#field53456823").val() + `",
"quantity": "` + jQuery("#field53456824").val() + `",
"discount_percentage": "` + jQuery("#field53456826").val().replace("%", "") + `",
"duration": "1"
}`
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/json');
//invocation.onreadystatechange = handler;
invocation.send(fifthProductData)
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment