最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Zoho CRM Workflow Function Not Receiving Field Data – All Values NULL - Stack Overflow

programmeradmin2浏览0评论

I am trying to do an automation using functions and workflow.

One of our clients has a request that they want to get an update about all of their sales orders on their application when the status of sales orders changes. I created a work flow rule, crete and edit, and if the account name is "client account name," then apply the function.

An automated category function is created to send SO_Number, Status, Deal_Name, Contact_Name to a
webhook url. later will be replaced by clients standard Mule Rest Callout with auth2.0 authentication.

My response is success, but no data is sent; all logs are showing the data point is null. I have forwarded the fields name and API name from Zoho API names only.

Response Logs:

Function Execution Started Received SO Number: NULL Received Status: NULL Received Deal Name: NULL Received Contact Name: NULL Received Account Name: NULL or Empty string standalone.sendSalesOrderToMule(Int sales_order_id)

Code

  {
// Fetch Sales Order details from Zoho CRM
sales_order = zoho.crm.getRecordById("SalesOrders, sales_order_id);
// Check if the Account Name is "Aldar Properties."
account_name = sales_order.get("Account_Name");
if(account_name != "Aldar Properties")
{
    return "No action taken—Not Aldar Properties";
}
// Extract required fields
so_number = sales_order.get("SO_Number");
status = sales_order.get("Status");
deal_name = sales_order.get("Deal_Name");
contact_name = sales_order.get("Contact_Name");
// Prepare JSON payload
data_map = Map();
data_map.put("so_number",so_number);
data_map.put("status",status);
data_map.put("deal_name",deal_name);
data_map.put("contact_name",contact_name);
// Convert Map to JSON string
json_payload = data_map.toString();
// Ensures proper JSON format
// Define Webhook URL (For now, we use a dummy API for testing)
webhook_url = ";;
//  Replace with MuleSoft API later
// Send POST request
response = invokeurl
[
    url :webhook_url
    type :POST
    parameters:json_payload
    headers:{"Content-Type":"application/json"}
];
// Log response for debugging
info response;
// Return success message
return "Webhook sent successfully!";
}
 Error: Account Name is empty!

Second Approach

void automation.sendAldarSalesOrderWebhook(String SO_Number)
{
// Validate input
if(SO_Number == null || SO_Number == "")
{
    info "Error: Empty Sales Order Number";
    return;
}
try 
{
    // Get Sales Order using SO_Number
    searchCriteria = "(SO_Number:equals:" + SO_Number + ")";
    SO_Number_Records = zoho.crm.searchRecords("SO_Number",searchCriteria);
    // Replaced "SalesOrders" with "SO_Number"
    // Validate that we found a matching SO_Number record
    if(SO_Number_Records == null || SO_Number_Records.isEmpty())
    {
        info "Error: No record found for SO_Number: " + SO_Number;
        return;
    }
    // Assuming SO_Number is unique, take the first match
    SO_Number_Record = SO_Number_Records.get(0);
    // Validate that the Account Name is "Aldar Properties"
    accountName = if(SO_Number_Record.containsKey("Account_Name") && SO_Number_Record.get("Account_Name") != null,SO_Number_Record.get("Account_Name").get("name"),"");
    if(accountName != "Aldar Properties")
    {
        info "Skipping: SO_Number record does not belong to Aldar Properties.";
        return;
    }
    // Build payload using safe field handling
    payloadMap = Map();
    // Add SO_Number
    payloadMap.put("SO_Number",SO_Number);
    // Handle Status
    status = if(SO_Number_Record.containsKey("Status") && SO_Number_Record.get("Status") != null,SO_Number_Record.get("Status"),"No Status");
    payloadMap.put("Status",status);
    // Handle Deal_Name
    dealName = if(SO_Number_Record.containsKey("Deal_Name") && SO_Number_Record.get("Deal_Name") != null,SO_Number_Record.get("Deal_Name").get("name"),"No Deal Linked");
    payloadMap.put("Deal_Name",dealName);
    // Handle Contact_Name
    contactName = if(SO_Number_Record.containsKey("Contact_Name") && SO_Number_Record.get("Contact_Name") != null,SO_Number_Record.get("Contact_Name").get("name"),"No Contact Linked");
    payloadMap.put("Contact_Name",contactName);
    // Log JSON payload before sending
    info "JSON Payload to Webhook:";
    info payloadMap;
    // Send webhook request
    response = invokeurl
    [
        url :";
        type :POST
        parameters:payloadMap
        headers:{"Content-Type":"application/json"}
        detailed:true
    ];
    // Log webhook response
    info "Webhook Response:";
    info response;
    if(response.containsKey("responseCode") && response.get("responseCode") != 200)
    {
        info " Webhook failed: " + response.get("responseText");
    }
    else
    {
        info " Webhook sent successfully.";
    }
}
catch (e)
{
    info " Error: Exception occurred - " + e.toString();
}
}
发布评论

评论列表(0)

  1. 暂无评论