How to wait process update finish ?

I have multiple apps for updates at same time.

How can I code (wait process update finish)?

Hi NewTum

Can you please provide a sample code of what you have tried out so far so that others, including me, can support you?

Thank you

Error updates at same time

 

kintone.events.on([‘app.record.detail.process.proceed’, ‘mobile.app.record.detail.delete.submit’], function(event) {
   var record = event.record;
   var status = event[‘nextStatus’].value;

   if(status == ‘Completed’){

      var table_PC = record.Table_2.value;
      var check_PC = table_PC[0].value[‘Lookup_2’].value;

      var table_IP = record.Table_3.value;
      var check_IP = table_IP[0].value[‘Lookup_3’].value;

      // ======================================= Invoice list (Project cost) =======================================
      if(table_PC.length > 0 && FT_Nullcheck(check_PC) != ‘’){
            var agreementNumber_PC = ‘’;

            // for loop store data set “Agreement Number” for query
           for(var i = 0; i < table_PC.length; i++){
               if(i != (table_PC.length - 1)){
                     agreementNumber_PC += ‘"’ + table_PC[i].value[‘Lookup_2’].value + ‘"’ + ', ';
               }else{
                     agreementNumber_PC += ‘"’ + table_PC[i].value[‘Lookup_2’].value + ‘"’;
               }
           }

           // data set query app “Project cost approval & Payment”
           var paramsPC = {
                    ‘app’: appId_PC,
                    ‘query’: ‘agree_no in (’ + agreementNumber_PC + ‘) order by agree_no asc’
           };

           kintone.api(kintone.api.url(’/k/v1/records’, true), ‘GET’, paramsPC).then(function(resp) {
               var recordPC = resp.records;
               var dataUpdatePC = new Array();

              // for loop for keeping records to be updated.
             for(var i = 0; i < recordPC.length; i++){
                   var dataPC = recordPC[i];
                   var recordNumberPC = dataPC[‘Record_number’].value;

                   var updatePC = {
                            “id”: recordNumberPC,
                            “record”: {
                                  “InvoiceListStatus”: {
                                            “value”: ‘Invoice’
                                   }
                             }
                  }
                 dataUpdatePC.push(updatePC);
             }

             if(dataUpdatePC.length > 0){
                  var body = {
                           “app”: appId_PC,
                           “records”: dataUpdatePC
                  }

                  UpdateData(appId_PC, dataUpdatePC);
             }

         }).catch(function(e) {
             // error
             console.log('Error occured update record app id ’ + ‘"’ + appId_PC + '" : ’ + e.message);
         });
     }
     // ===================================== End Invoice list (Project cost) =====================================

     // ==================================== Invoice list (Internal Purchase) =====================================
     if(table_IP.length > 0 && FT_Nullcheck(check_IP) != ‘’){
           var purchaseNumber_IP = ‘’;

           // for loop store data set “Agreement Number” for query
           for(var i = 0; i < table_IP.length; i++){
                  if(i != (table_IP.length - 1)){
                          purchaseNumber_IP += ‘"’ + table_IP[i].value[‘Lookup_3’].value + ‘"’ + ', ';
                  }else{
                          purchaseNumber_IP += ‘"’ + table_IP[i].value[‘Lookup_3’].value + ‘"’;
                  }
           }

           // data set query app “Internal Purchase /Payment”
           var paramsIP = {
                   ‘app’: appId_IP,
                   ‘query’: ‘pur_no in (’ + purchaseNumber_IP + ‘) order by pur_no asc’
           };

           kintone.api(kintone.api.url(’/k/v1/records’, true), ‘GET’, paramsIP).then(function(resp) {
                var recordIP = resp.records;
                var dataUpdateIP = new Array();

                // for loop for keeping records to be updated.
                for(var i = 0; i < recordIP.length; i++){
                       var dataIP = recordIP[i];
                       var recordNumberIP = dataIP[‘Record_number’].value;

                       var updateIP = {
                                 “id”: recordNumberIP,
                                 “record”: {
                                       “InvoiceListStatus”: {
                                                  “value”: ‘Invoice’
                                        }
                                  }
                        }
                        dataUpdateIP.push(updateIP);
                }

                if(dataUpdateIP.length > 0){
                      var body = {
                             “app”: appId_IP,
                             “records”: dataUpdateIP
                      }

                      UpdateData(appId_IP, dataUpdateIP);
                  }

               }).catch(function(e) {
                     // error
                     console.log('Error occured update record app id ’ + ‘"’ + appId_IP + '" : ’ + e.message);
               });
            }
           // ================================== End Invoice list (Internal Purchase) ===================================

      return event;
});

function UpdateData(appId, dataUpdate){

if(dataUpdate.length > 0){
var body = {
“app”: appId,
“records”: dataUpdate
}

kintone.api(kintone.api.url(’/k/v1/records’, true), ‘PUT’, body).then(function(resp) {
// success
console.log(‘Update app id : ’ + appId + ’ Success’);

}).catch(function(e) {
// error
console.log('Error occured update record app id : ’ + ‘"’ + appId + '" : ’ + e.message);
});
}
}

Hello NewTum,

 

After checking the code, for apps with app IDs of “appId_PC” and “appId_IP,”
it was ready to update the record when it reaches the status of “Completed.”

 

However, when I wrote the code, there were some problems, such as a lack of “{}'s.”
The error was outputting, so it may not be working itself.

 

With that being said, could you please check the following and provide more information?

 

・What kind of phenomenon occurs, such as not being able to process updates for multiple apps?

 

・Is there an erroron the console screen when you change the status to “Completed”?

 

・Does the same phenomenon occurs when only the minimum processing, such as record update processing?

 

・For more information on coding details waiting for the process to finish updating
(Do you want to update multiple app records when the details screen appears after reaching the status of “Completed”?)

 

I’d like to know the details of the order of processing.

Thanks