I have requirement for bulk task creation on button click. Consider if there are five task under different requests, based on task type I am changing task status and for status changed tasks we have to create one more task with different task type and different task status and requestid accordingly.
Example:
task id =102 ,request id =1002 and status = open
task id =103,request id =1003 and status =open
task id =104,request id =1004 and status =open
task id =105 ,request id =1005 and status =open
For all the above tasks status should be changed and 4 more task should be created with different task type and status like
task id =121,request id = 1002 and status = hold
task id =122,request id = 1003 and status = hold
task id =123,request id = 1004 and status = hold
task id =124,request id = 1005 and status = hold
Please suggest how can I achieve this through client scrip.
Regards,
Ramya
Best answer by Atheeq Maharoof
Hi @RamyaR ,
You can achieve your requirement by writing a client script for a button in the web client.
Following is the Client script written .
Client Script
I have defined 2 DB scripts
DB Scripts
Client Script
var requests = getDBValues("REQUEST_WITH_TYPE_FILTER"); if (isNullOrEmptyString(requests) != true ){ for (req_index = 0; req_index < requests.length; ++req_index){
var tasks = getDBValues("GET_TASKS_FOR_REQUEST", [requests[req_index]["request_id"]]); if (isNullOrEmptyString(tasks) != true ){ for(task_index = 0 ; task_index < tasks.length; ++task_index) { // Update status var updateRequest = createInsertUpdateRequest( 'task',{task_id : tasks[task_index]["task_id"],task_status :tasks[task_index]["task_status"]} ); var updateResponse = executeRequest(updateRequest); if (updateResponse != null && updateResponse.$type == 'ErrorResponse') { displayUserToast(updateResponse.message, 'error'); } } // Create new task var request = createInsertRequest( 'task' , {request_id : requests[req_index]["request_id"], plan_start_dttm : tasks[task_index]["plan_start_dttm"], plan_end_dttm : tasks[task_index]["plan_end_dttm"]}); var response = executeRequest(request); if (response != null && response.$type == 'ErrorResponse') { displayUserToast(response.message, 'error'); } } } } }
GET_TASKS_FOR_REQUEST - SELECT * from task where request_id = '{0}' REQUEST_WITH_TYPE_FILTER - SELECT * from request where req_type IN ('BASIC','FIX')
I have assigned the client script to a button in request search screen. Following are the output before and after button click. (Note - I commented the update status part and carried out the process, therefore the status change of the old task is not reflected)
When writing the createInsertUpdate request, make sure to include the required fields if not you will be getting an error stating the fields are mandatory. I did not test the solution entirely, but I think it caters for your requirement.
You can achieve your requirement by writing a client script for a button in the web client.
Following is the Client script written .
Client Script
I have defined 2 DB scripts
DB Scripts
Client Script
var requests = getDBValues("REQUEST_WITH_TYPE_FILTER"); if (isNullOrEmptyString(requests) != true ){ for (req_index = 0; req_index < requests.length; ++req_index){
var tasks = getDBValues("GET_TASKS_FOR_REQUEST", [requests[req_index]["request_id"]]); if (isNullOrEmptyString(tasks) != true ){ for(task_index = 0 ; task_index < tasks.length; ++task_index) { // Update status var updateRequest = createInsertUpdateRequest( 'task',{task_id : tasks[task_index]["task_id"],task_status :tasks[task_index]["task_status"]} ); var updateResponse = executeRequest(updateRequest); if (updateResponse != null && updateResponse.$type == 'ErrorResponse') { displayUserToast(updateResponse.message, 'error'); } } // Create new task var request = createInsertRequest( 'task' , {request_id : requests[req_index]["request_id"], plan_start_dttm : tasks[task_index]["plan_start_dttm"], plan_end_dttm : tasks[task_index]["plan_end_dttm"]}); var response = executeRequest(request); if (response != null && response.$type == 'ErrorResponse') { displayUserToast(response.message, 'error'); } } } } }
GET_TASKS_FOR_REQUEST - SELECT * from task where request_id = '{0}' REQUEST_WITH_TYPE_FILTER - SELECT * from request where req_type IN ('BASIC','FIX')
I have assigned the client script to a button in request search screen. Following are the output before and after button click. (Note - I commented the update status part and carried out the process, therefore the status change of the old task is not reflected)
When writing the createInsertUpdate request, make sure to include the required fields if not you will be getting an error stating the fields are mandatory. I did not test the solution entirely, but I think it caters for your requirement.