Automated Deal Scores

SOLA Group
SOLA Group Posts: 3
edited July 27 in Apps and Integrations #1

Hi all

I'm looking to add an automated "Deal Score" field which depends on some user-entered custom fields. Not a very complicated process, but after a bit of digging, it doesn't seem like it is going to be possible without some sort of added webhook integration from another service. 

Essentially, I need to take a few fields which a user enters when they create a new "Deal" and calculate a "deal score" which is a weighted sum of these values. Some of the values have to be mapped from a text input to a predefined corresponding score number... so some "if" statement functionality would probably be necessary. 

I have created a basic setup using Zapier, which works, but I have a couple issues with it:

  • The membership for Zapier (including "paths", their strange version of 'if' statements which I need for the mappings) is expensive. And furthermore, I think it would only cover functionality for my account and not my team members.
  • I have found editing functions in Zapier to be quite a lengthily process
  • The new "Deal Scores" do not get updated as instantly as I'd like them to (depending on internet connection)

Anyone know if there is a better way to do this? First prize would be to do it within Pipedrive. Second prize - another app which is cheaper/better that Zapier?

Thanks :)

Comments

  • Fabrizio Nicolosi_33821
    edited February 25 #2

    Hi my suggest is using api to do this kind of things because zapier is not too much stable. This is my experience. Let me know if you need help on that.

  • SOLA Group
    SOLA Group Posts: 3
    edited April 2021 #3

    Hi my suggest is using api to do this kind of things because zapier is not too much stable. This is my experience. Let me know if you need help on that.

    Thank you. I'm going to look into it a bit, was hoping to find an easier way. I may well get in touch with you for some help.

  • Steve Robinson_992
    Steve Robinson_992 Posts: 10
    edited April 2021 #4

    You might consider a Google cloud function. A little more technical to code, but would be instant and cheap to run. 
     

    if you need  some configuration, you could create a Google sheet with the configuration values. There’s a way to use Google apps script to receive webhooks and call apis. 

  • Kurt Jones_71
    Kurt Jones_71 Posts: 51
    Solution Provider
    edited April 2021 #5

    We've done this several times. There's no shortcut for it, and for the moment, the calculations have to be hardcoded. Everything you need is in the updated.deal and added.deal webhooks which fire whenever a deal is updated or added. You need to receive this data, which is everything related to the deal AFTER the update or add was done. Pick the fields you need, apply the calculation and then use PUT/deals/{id} api call to update the deal. Whole process should take about a second.

     

  • SOLA Group
    SOLA Group Posts: 3
    edited April 2021 #6

    Thank you all very much for your help.

    I ended up going with an Apps Script implementation (the direct connection to a google spreadsheet will be useful for me later on).

    I found this  article helpful for understanding the webhook implementation.

    Here is the code I have set up thus far for testing purposes. It seems to work great, so I'll leave it here incase someone else finds it useful.

    // "Get" request function (not used)
    function doGet(e) {
      return HtmlService.createHtmlOutput("get request recieved :)")
    }
    
    // Function to be implemented on a "post" request, which will be triggered by the Pipedrive webhook
    function doPost(e){
    
      // Interpret the recieved data (in JSON format) 
      var myData = JSON.parse(e.postData.contents);
      
      // Isolate the relevant deal fields
      var dealID = myData.current.id;
      var customFieldX = myData.current["20190709d83a418621991c3c0573a695cab7d137"];
    
      // Get some data from the current spreadsheet
      var sheet = SpreadsheetApp.getActiveSheet();
      var gSheetValue = sheet.getRange("D1").getValue();
    
      // Calculate new value for the custom field, "Deal Score" with API key, "27c95d3a212ac9d976b1ac77d25a44ba66d0de0f"
      var newDealScore = customFieldX + gSheetValue;
    
      // Send "put" request to deal with the ID found above ("dealID"), with new data for the "Deal Score" custom field
      var url = "https://solagroup2.pipedrive.com/api/v1/deals/" + dealID + "?api_token=YOURAPITOKENNOTMINE";
      var data = {
          "27c95d3a212ac9d976b1ac77d25a44ba66d0de0f": newDealScore
      };
      var options = {
          "method": "put",
          'contentType': 'application/json',
          "payload": JSON.stringify(data)
      };
      var response = UrlFetchApp.fetch(url, options);
    
      return HtmlService.createHtmlOutput("post request recieved");
    }