Skip to content

Instantly share code, notes, and snippets.

@jeznag
Last active March 31, 2019 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeznag/eb53f5742c6f9cebf3b6752b04fd25e2 to your computer and use it in GitHub Desktop.
Save jeznag/eb53f5742c6f9cebf3b6752b04fd25e2 to your computer and use it in GitHub Desktop.
Automatically associating products to potential in Zoho CRM
AUTH_TOKEN = "CHANGEME";
quote_record = zoho.crm.getRecordById("Quotes", quote_id);
quote_products = quote_record.get("product").toJSONList();
related_products = zoho.crm.getRelatedRecords("Products", "Potentials", input.deal_id.toString());
row_index = 1;
xml_data = "<Products>";
for each product in quote_products {
product_map = product.toMap();
info product_map;
xml_data += "<row no=\"" + row_index + "\"><FL val=\"PRODUCTID\">" + product_map.get("Product Id") + "</FL></row>";
row_index += 1;
}
xml_data += "</Products>";
info xml_data;
UPDATE_RELATED_RECORDS_URL = "https://crm.zoho.com/crm/private/json/Potentials/updateRelatedRecords?authtoken="+ AUTH_TOKEN +"&scope=crmapi&id=" + deal_id + "&relatedModule=Products&xmlData=" + xml_data;
update_related_resp = getUrl(UPDATE_RELATED_RECORDS_URL);
Copy link

ghost commented Mar 16, 2018

Hi,

I attempted to use this as our Implementation team didn't want to have to add products to the Quotes, then the Potentials, and then the accounts. I'm not able to get the function to run. I was able to find one from the market place that rolled the products from Potentials to Accounts but it won't work either.

Here is that code:
stage = stage;
if(stage.contains("Won"))
{
url = "https://crm.zoho.com/crm/private/xml/Organizations/updateRelatedRecords?";
potentialIdStr = potentialId.toString();
relatedProducts = zoho.crm._getRelatedRecords("Products","Potentials",potentialIdStr,1,100);
//It will fetch 100 Records associated with Potentails
mapVariable = Map();
mapVariable.put("authtoken",authToken);
mapVariable.put("scope","crmapi");
allProductXmlData = "";
rowVariable = 1;
for each product in relatedProducts
{
productId = product.get("PRODUCTID");
ProductXmlData = "<row no="" + rowVariable + ""><FL val="PRODUCTID">" + productId + "";
rowVariable = rowVariable + 1;
allProductXmlData = allProductXmlData + ProductXmlData;
}
allProductXmlData = allProductXmlData + "";
mapVariable.put("xmlData",allProductXmlData);
mapVariable.put("relatedModule","Products");
mapVariable.put("id",accountId.toString());
updatedResponse = postUrl(url,mapVariable);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment