Creating Tickets In Zoho desk

Creating Tickets In Zoho desk

HI,
  Iam trying to create tickets in Zoho desk whenever a sales order is created. I want to create the tickets based on the product name.
 I had written this function but the ticket was creating with other product name. Can anyone help me with this issue?

Function:

  res = zoho.crm.getRecordById("Sales_Orders",soid);
contid = ifnull(res.get("Contact_Name").get("id"),"");
resp = zoho.crm.getRecordById("Contacts",contid);
mp = Map();
email = ifnull(resp.get("Email"),"");
resp = res.get("Product_Details");
for each  ele in resp
{
name = ele.get("Product_Name");
searchValue1 = {"productName":name};
info searchValue1;
pro = zoho.desk.searchRecords(------,"products",searchValue1);
info pro;
value1 = pro.get("data").toJSONList();
id1 = value1.get(0).get("id");
info id1;
mp.put("productId",id1);
searchValue = {"email":email};
search = zoho.desk.searchRecords(------,"Contacts",searchValue);
value = search.get("data").toJSONList();
id = value.get(0).get("id");
info id;
searchValue1 = {"productName":name};
pro = zoho.desk.searchRecords(-----,"products",searchValue1);
value1 = pro.get("data").toJSONList();
id1 = value1.get(0).get("id");
info id1;
mp = Map();
mp.put("productId",id1);
mp.put("subject","name");
mp.put("contactId",id);
mp.put("departmentId",---------);
mp.put("category","general");
mp.put("email",email);
crea = zoho.desk.create(--------,"tickets",mp);
info crea;
}

 I had tested by using my Dept Id and Org Id.

Thanks