Hi,
I have products on the CRM with a picklist field called Status that is set to Published, Draft or Pending Review.
Products are added to quotes naturally with the subform Quoted_Items.
I want to update a picklist field on the quotes module (called Valid_Quote) with either Yes or No based on whether any products added to the quote are published or not.
If all products are published then = Yes. If any one is not published = No.
Here is my code:
quoteIdStr = input.Quote_ID.toString();
quoteMap = zoho.crm.getRecordById("Quotes", input.Quote_ID);
productDet = ifnull(quoteMap.get("Quoted_Items"),"");
productList = productDet.toJSONList();
statusCheck = "Published";
isValid = false; // Assuming all products are valid initially
continueChecking = true; // Flag to determine whether to continue checking products
for each eachProd in productList
{
if (continueChecking)
{
eachProdDet = eachProd.toMap();
productId = ifnull(eachProdDet.get("Product Id"),"");
proDetails = zoho.crm.getRecordById("Products", productId.toLong());
productStatus = proDetails.get("Status"); // Assuming "Status" is the field name in the Products module
if (productStatus != statusCheck)
{
isValid = false;
continueChecking = false; // Set the flag to false to skip checking the remaining products
}
}
}
params = map();
if (isValid)
{
params.put("Valid_Quote", "Yes");
}
else
{
params.put("Valid_Quote", "No");
}
updateResp = zoho.crm.updateRecord("Quotes", quoteIdStr, params);
Function runs but just defaults to whatever is set initially on isValid.