Untitled

 avatar
Venkat
plain_text
2 years ago
6.0 kB
3
Indexable
// TODO: Please create a connection for the Zoho Projects service with the scopes " ZohoProjects.tasks.READ ". Replace 'xxxxxxxxx' with the connection name. Click this link to learn how to create the connection. 
// Link - https://help.zoho.com/portal/en/kb/projects/integration/connections/articles/connections-23-5-2022#How_to_establish_a_Connection
// TODO: Please create a connection for the ZohoCliq service with the scopes " ZohoCliq.Webhooks.CREATE ". Replace 'yyyyyyyyy' with the connection name.
// TODO : Replace the channel Unique Name
channelUniqueName = "dbmigrationnotification";
taskCreateContent = "[user] has created a new task [taskId] in project *[project-name]*" + ". The query to check the migration is " + TestQuery + ". The task is assigned to " + ownerName + ". The className is : " + taskName + ". The deployment is : " + deployment;
taskUpdateContent = "[user] has updated the [action] of the task [taskId] from *[pre-value]* to *[post-value]*";
taskBulkUpdateContent = "[user] has updated task [taskId]";
taskBulkUpdateSubContent = "[action] from *[pre-value]* to *[post-value]*";
taskDeleteContent = "[user] has deleted the task *[task-name]*";
//query = "[q"
// Sample affected fields value while update task 
//affectedFields = {"action_time":"2022-03-23 23:22:59.889","module":"task","edits":{{"old_value":"In Review","new_value":"Testing","field_name":"Status"}},"action":"Update","user":{"zpuid":"1752587000000036003","name":"Vignesh J","zuid":"738624987"}};
// Sample affected fields value while create task 
//affectedFields = {"action_time":"2022-02-21 10:17:25.3","module":"task","edits":[{"task_name":"test task","task_id":"12000000292019"}],"action":"Creation","user":{"zpuid":"12000000000963","name":"Vignesh J","zuid":"738624987"}};
// Sample affected fields value while delete task 
//affectedFields = {"action_time":"2022-02-21 10:17:58.054","module":"task","edits":[{"task_name":"test task","task_id":"12000000292019"}],"action":"Deletion","user":{"zpuid":"12000000000963","name":"Vignesh J","zuid":"738624987"}};
// ZohoProjects API Endpoint
projectsDomainURL = "https://projects.zoho.com/portal/iotcloud#todomilestones/1030201000001003037";
messageContent = "";
info affectedFields;
if(!affectedFields.isNull() && affectedFields.contains("edits"))
{
	info affectedFields.get('edits');
	action = affectedFields.get("action");
	user = affectedFields.get("user");
	if(action == "Creation")
	{
		taskResponse = zoho.projects.getRecordById(portalId,projectId,"tasks",taskId,"projectsformigration");
		taskInfo = taskResponse.get("tasks").get(0);
		taskCreateContent = taskCreateContent.replaceAll("[user]","[" + user.get("name") + "](zohoid:" + user.get("zuid") + ")",true);
		taskCreateContent = taskCreateContent.replaceAll("[taskId]","[" + taskInfo.get("key") + "](" + taskInfo.get("link").get("web").get("url") + ")",true);
		messageContent = taskCreateContent.replaceAll("[project-name]",projectName,true);
	}
	else if(action == "Update")
	{
		taskResponse = zoho.projects.getRecordById(portalId,projectId,"tasks",taskId,"projectsformigration");
		taskInfo = taskResponse.get("tasks").get(0);
		info affectedFields.get("edits").size();
		if(affectedFields.get("edits").size() == 1)
		{
			url = "[" + taskInfo.get("key") + "](" + taskInfo.get("link").get("web").get("url") + ")";
			info url;
			taskBulkUpdateContent = taskBulkUpdateContent.replaceAll("[taskId]",url,true);
			taskBulkUpdateContent = taskBulkUpdateContent.replaceAll("[user]","[" + user.get("name") + "](zohoid:" + user.get("zuid") + ")",true);
			for each  fields in affectedFields.get('edits')
			{
				subcontent = taskBulkUpdateSubContent;
				subcontent = subcontent.replaceAll("[action]",fields.get("field_name"),true);
				subcontent = subcontent.replaceAll("[pre-value]",fields.get("old_value"),true);
				subcontent = subcontent.replaceAll("[post-value]",fields.get("new_value"),true);
				taskBulkUpdateContent = taskBulkUpdateContent + "\n" + subcontent;
			}
			messageContent = taskBulkUpdateContent;
		}
		else
		{
			fields = affectedFields.get("edits").get(0);
			taskUpdateContent = taskUpdateContent.replaceAll("[taskId]","[" + taskInfo.get("key") + "](" + taskInfo.get("link").get("web").get("url") + ")",true);
			taskUpdateContent = taskUpdateContent.replaceAll("[user]","[" + user.get("name") + "](zohoid:" + user.get("zuid") + ")",true);
			taskUpdateContent = taskUpdateContent.replaceAll("[action]",fields.get("field_name"),true);
			taskUpdateContent = taskUpdateContent.replaceAll("[pre-value]",fields.get("old_value"),true);
			taskUpdateContent = taskUpdateContent.replaceAll("[post-value]",fields.get("new_value"),true);
			messageContent = taskUpdateContent;
		}
	}
	else if(action == "Deletion")
	{
		taskDeleteContent = taskDeleteContent.replaceAll("[user]","[" + user.get("name") + "](zohoid:" + user.get("zuid") + ")",true);
		messageContent = taskDeleteContent.replaceAll("[task-name]",taskName,true);
	}
}
if(affectedFields.isNull())
{
	messageContent = "AffectedFieldsNull";
}
if(!affectedFields.isNull() && !affectedFields.contains("edits"))
{
	messageContent = "AffectedFieldsNoEdits";
}
if(messageContent == "")
{
	messageContent = "task";
}
info "message:" + messageContent;
if(messageContent == "")
{
	messageContent = taskCreateContent;
}
if(messageContent != null && !messageContent.isEmpty())
{
	chat = zoho.cliq.postToChannel(channelUniqueName,messageContent,"cliqformigration");
	info chat;
}
return "success";
// TODO: Please create a connection for the Zoho Projects service with the scopes " ZohoProjects.tasks.READ ". Replace 'xxxxxxxxx' with the connection name. Click this link below to learn how to create the connection.
// Link - https://help.zoho.com/portal/en/kb/projects/integration/connections/articles/connections-23-5-2022#How_to_establish_a_Connection
// TODO: Please create a connection for the ZohoCliq service with the scopes " ZohoCliq.Webhooks.CREATE ". Replace 'yyyyyyyyy' with the connection name.
Editor is loading...