Field name | Field Type | Description |
Share in | Select | The user should select where they want to share the URL. Either in a channel or another user's direct message. The value of 'trigger on change' attribute of this field should be set as 'true'. Based on the user input in this field, the next field (channel name / user name) should be displayed. |
Users | multiSelect | Select the people to share the URL with. |
Channels | multiSelect | The user should select the Cliq channels in which the URL should be shared |
Message | textArea | The content for the message to be shared. |
fields.add({"type":"select","label":"Share in","name":"sharein",
"hint":"Select where you’d like to share this post",
"mandatory":"true","triggerOnChange":"true",
"options":{{"label":"Direct Message","id":"private"},
{"label":"Channel","id":"channel"}},"value":"private"});
fields.add({"type":"multiSelect","label":"Users",
"name":"users","mandatory":"true",
"triggerOnChange":"false","dataSource":"user"});
channels = Map();allChannel = list();countList = {"1","2","3","4","5"};//for each count in countList{parameterMap = Map();if(channels.containKey("next_token")){parameterMap.put("next_token",channels.get("next_token"));}channels = invokeurl[type :GETparameters:parameterMapconnection:"zohocliqoauth"];channels = channels.toMap();channelsList = channels.get("channels").toList();for each channel in channelsList{option = Map();option.put("id",channel.get("channel_id"));option.put("value",channel.get("unique_name"));option.put("label",channel.get("name"));allChannel.add(option);}if(channels.containKey("has_more") == false || channels.get("has_more") == false){break;}}
fields.add({"type":"multiSelect","label":"Channels","name":"channel",
"mandatory":"true","triggerOnChange":"false","options":allChannel,"hide":"true"});
message = "Look this [connect post](" + entity.get("url") + ")";fields.add({"type":"textArea","label":"Message",
"name":"message","hint":"Enter your message",
"mandatory":"true","triggerOnChange":"false","value":message,"maxLimit":1000});
fields = {};fields.add({"type":"select","label":"Via","name":"sharein",
"hint":"Select where you’d like to share this post",
"mandatory":"true","triggerOnChange":"true",
"options":{{"label":"Direct Message","id":"private"},
{"label":"Channel","id":"channel"}},"value":"private"});channels = Map();allChannel = list();countList = {"1","2","3","4","5"};//for each count in countList{parameterMap = Map();if(channels.containKey("next_token")){parameterMap.put("next_token",channels.get("next_token"));}channels = invokeurl[type :GETparameters:parameterMapconnection:"zohocliqoauth"];channels = channels.toMap();channelsList = channels.get("channels").toList();for each channel in channelsList{option = Map();option.put("id",channel.get("channel_id"));option.put("value",channel.get("unique_name"));option.put("label",channel.get("name"));allChannel.add(option);}if(channels.containKey("has_more") == false || channels.get("has_more") == false){break;}}fields.add({"type":"multiSelect","label":"Channels",
"name":"channel","mandatory":"true","triggerOnChange":"false",
"options":allChannel,"hide":"true"});fields.add({"type":"multiSelect","label":"Users","name":"users",
"mandatory":"true","triggerOnChange":"false","dataSource":"user"});message = "Look this [connect post](" + entity.get("url") + ")";fields.add({"type":"textArea","label":"Message","name":"message",
"hint":"Enter your message","mandatory":"true",
"triggerOnChange":"false","value":message,"maxLimit":1000});form = Map();form.put("title","Share in Cliq");form.put("hint","Share a Connect post in Cliq");form.put("buttonLabel",{"done":"Share"});form.put("fields",fields);returnMap = Map();returnMap.put("form",form);return returnMap;
targetEle = target.get("name");formValues = form.get("values");fieldList = form.get("fields").toList();returnMap = Map();if(targetEle == "sharein"){cliqMedium = formValues.get("sharein").toMap().get("id");fields = list();if(cliqMedium == "private"){fields.add({"name":"channel","hide":true});fields.add({"name":"users","hide":false});}else{fields.add({"name":"users","hide":true});fields.add({"name":"channel","hide":false});}returnMap.put("fields",fields);}return returnMap;
message = form.get("values").get("message");channels = form.get("values").get("channel").toList();info channels;errorMsg = "";joiner = "";for each channel in channels{response = zoho.cliq.postToChannel(channel.get("value"),
message,"zohocliqoauth");info response;if(response == null || response.containKey("status") == false ||
response.get("status") != "success"){errorMsg = errorMsg + joiner + channel.get("label");joiner = ", ";info channel.get("value") + " :::: " + response;}}
users = form.get("values").get("users").toList();info users;for each cliqUser in users{if(cliqUser.get("id") == user.get("id")){fieldError = Map();fieldError.put("users","You cannot share a post with yourself.");returnMap.put("fieldError",fieldError);return returnMap;}}
for each cliqUser in users{response = zoho.cliq.postToUser(cliqUser.get("value"),message,"zohocliqoauth");info response;if(response == null || response.containKey("status") == false ||
response.get("status") != "success"){errorMsg = errorMsg + joiner + cliqUser.get("label");if(response.containKey("message")){info cliqUser.get("value") + " :::: " + response.get("message");}}}
if(errorMsg != null && errorMsg.length() > 0){msg = "";if(cliqMedium == "channel"){msg = "Sorry, we’re unable to share the post in the following channel(s): "
+ errorMsg;}else{msg = "Sorry, we’re unable to share the post with the following user(s): "
+ errorMsg;}returnMap.put("result","success");returnMap.put("message",msg);}else{returnMap.put("result","success");returnMap.put("message","Message shared successfully");}
returnMap = Map();formValues = form.get("values");cliqMedium = formValues.get("sharein").toMap().get("id");info cliqMedium;message = formValues.get("message");errorMsg = "";joiner = "";if(cliqMedium == "channel"){channels = formValues.get("channel").toList();info channels;for each channel in channels{response = zoho.cliq.postToChannel(channel.get("value"),message,"zohocliqoauth");info response;if(response == null || response.containKey("status") == false ||
response.get("status") != "success"){errorMsg = errorMsg + joiner + channel.get("label");joiner = ", ";info channel.get("value") + " :::: " + response;}}}else{users = formValues.get("users").toList();info users;for each cliqUser in users{if(cliqUser.get("id") == user.get("id")){fieldError = Map();fieldError.put("users","You cannot share a post with yourself.");returnMap.put("fieldError",fieldError);return returnMap;}}for each cliqUser in users{response = zoho.cliq.postToUser(cliqUser.get("value"),message,"zohocliqoauth");info response;if(response == null || response.containKey("status") == false ||
response.get("status") != "success"){errorMsg = errorMsg + joiner + cliqUser.get("label");if(response.containKey("message")){info cliqUser.get("value") + " :::: " + response.get("message");}}}}if(errorMsg != null && errorMsg.length() > 0){msg = "";if(cliqMedium == "channel"){msg = "Sorry, we’re unable to share the post in the following channel(s):
" + errorMsg;}else{msg = "Sorry, we’re unable to share the post with the following user(s):
" + errorMsg;}returnMap.put("result","success");returnMap.put("message",msg);}else{returnMap.put("result","success");returnMap.put("message","Message Shared Successfully");}return returnMap;