变更触发器用例

变更触发器用例

1) 在变更关闭期间,关闭由变更发起的请求。

  • 设置触发器在编辑过程中对所有变更执行。
  • 设置触发器在变更状态为已完成 >> 关闭时执行。
  • 选择在编辑变更条件中的任何字段时执行触发器。
  • 执行以下自定义函数:
id = changeObj.get("id");

params = Map();

// fetching requests initiated by this change

response = zoho.sdp.invokeurl

[

url :"/api/v3/changes/" + id + "/initiated_requests"

type :GET

parameters:params

];

requests = response.get("initiated_requests");

close_success_requests = "Closed Requests ID : ";

close_failed_requests= "Unclosed Requests ID : ";

for each  request in requests

{

associated_request_id = request.get("request").get("id");

        // trying to close the request

close_response = zoho.sdp.invokeurl

[

url :"/api/v3/requests/" + associated_request_id + "/close"

type :PUT

];

        // request close is unsuccessful

if(close_response.get("response_status").get("status_code") != 2000 && close_response.get("response_status").get("messages").get(0).get("status_code") != 4007)

{

close_failed_requests= close_failed_requests+ request.get("request").get("id") + ", ";

note = zoho.sdp.invokeurl

[

url :"/api/v3/requests/" + associated_request_id + "/notes"

type :POST

parameters:{"input_data":{"request_note":{"description":"Associated change with ID " + id + " is closed"}}}

];

}

else if(close_response.get("response_status").get("messages").get(0).get("status_code") == 4007)   // request is already closed

{

close_success_requests = close_success_requests + request.get("request").get("id") + ", ";

}

else

{

close_success_requests = close_success_requests + request.get("request").get("id") + ", ";

}

}

description = close_success_requests + "<br>" + close_failed_requests+ "<br>";

change_description = "<h3>Change Initiated Requests are closed as the change has been moved to closed state<br>Status:-<br></h3>" + description;

notes = zoho.sdp.invokeurl

[

url :"/api/v3/changes/" + id + "/notes"

type :POST

parameters:{"input_data":{"note":{"description":change_description}}}

];