I do button to do Mass Update to submit in Process management but I got an error

Dear Expert, kindly users

I do my kintone and I would like a button to submit for approval for mass records like my image. and i embed process management flow


I don't know, what's wrong but I got an error when I press a button and i don't know how to debug.
Note this is a first point that I checked:

  • "action is invalid" → I check and I found I have an action name 'Submit'.
  • "No permission" → Now I'm administrator and I create records by myself and when I check to submit if I do manual I can submit.
  • "Record is not in the correct status" → this is starting point to request submit.

Here is my code on java script
(function() {
'use strict';

kintone.events.on('app.record.index.show', function(event) {
// Prevent duplication of the button
if (document.getElementById('my_index_button') !== null) {
return;
}

// Create a button
var myIndexButton = document.createElement('button');
myIndexButton.id = 'my_index_button';
myIndexButton.innerHTML = 'Submit for Approval';
myIndexButton.style.marginLeft = '10px';
myIndexButton.style.backgroundColor = '#28a745';
myIndexButton.style.color = 'white';
myIndexButton.style.border = 'none';
myIndexButton.style.padding = '8px 12px';
myIndexButton.style.cursor = 'pointer';

// Button onclick function
myIndexButton.onclick = async function() {
  if (!window.confirm('Are you sure you want to submit all records for Manager approval?')) {
    return;
  }

  // Get records from the current page
  var records = event.records;
  if (!records || records.length === 0) {
    alert('No records found.');
    return;
  }

  // Prepare workflow update payload
  var workflowActions = records.map(record => ({
    app: kintone.app.getId(),
    id: record.$id.value, // Record ID
    action: 'Submit' // Action name in the workflow
  }));

  try {
    // Process workflow for each record
    for (let action of workflowActions) {
      await kintone.api(kintone.api.url('/k/v1/record/status', true), 'PUT', action);
    }
    alert('Successfully submitted records for Manager approval.');
  } catch (error) {
    console.error(error);
    alert('Error submitting records. Check console for details.');
  }
};

// Add button to header menu space
kintone.app.getHeaderMenuSpaceElement().appendChild(myIndexButton);

});
})();

//Submit =>Manager

Hello @Metalone

The issue might be related to the assignee field not being specified in your API call. According to Kintone’s documentation, the assignee parameter is required if the "Assignee List" for the current status is set to "User chooses one assignee from the list to take action", and there are selectable assignees available.

Could you check if that’s the case in your process management settings?

**thanks for contributing! @Chris I can do for all record but I would like to added value for it.
this is my sceanrio, I have a lot of record and I would like to click and code need to filter status only "Applicant by" to take action but it doesn't work.

Can you guide me what's wrong? my code is below.


(function() {
'use strict';

kintone.events.on('app.record.index.show', function(event) {
if (document.getElementById('my_index_button') !== null) {
return;
}

var myIndexButton = document.createElement('button');
myIndexButton.id = 'my_index_button';
myIndexButton.innerHTML = 'Submit for Manager Approval';
myIndexButton.style.marginLeft = '10px';
myIndexButton.style.backgroundColor = '#28a745';
myIndexButton.style.color = 'white';
myIndexButton.style.border = 'none';
myIndexButton.style.padding = '8px 12px';
myIndexButton.style.cursor = 'pointer';

myIndexButton.onclick = async function() {
  if (!window.confirm('Are you sure you want to submit records with status "Applicant By" for Manager approval?')) {
    return;
  }

  var records = event.records;
  if (!records || records.length === 0) {
    alert('No records found.');
    return;
  }

  var assigneeUserCode = 'thanakorn.k'; // Change to the actual login name or group name

  // Filter records where status = "Applicant By"
  var workflowActions = records
    .filter(record => record.status && record.status.value === "Applicant By")
    .map(record => ({
      id: record.$id.value,
      action: 'Submit',
      assignee: assigneeUserCode
    }));

  if (workflowActions.length === 0) {
    alert('No records with status "Applicant By" found.');
    return;
  }

  try {
    console.log("Manager User Code:", assigneeUserCode);
console.log(kintone.api.url('/k/v1/records/status', true));
console.log("Workflow Actions Payload:", JSON.stringify(workflowActions, null, 2));
    var response = await kintone.api(kintone.api.url('/k/v1/records/status', true), 'PUT', {
      app: kintone.app.getId(),
      records: workflowActions
    });

    alert(`Successfully submitted ${workflowActions.length} records for Manager approval.`);
  } catch (error) {
    console.error('API Error:', error);
    alert('Error submitting records. Check the console for details.');
  }
};

kintone.app.getHeaderMenuSpaceElement().appendChild(myIndexButton);

});
})();

Dear All,
Thank you for your guideline now I got my solution.
like code below

(function() {
'use strict';

kintone.events.on('app.record.index.show', function(event) {
// Prevent adding the button multiple times
if (document.getElementById('testbtn') !== null) {
return;
}

// Create the button
var testbtn = document.createElement('button');
testbtn.id = 'testbtn';  // Set the new button ID
testbtn.innerHTML = 'Submit for Manager Approval(Only Status Applicant By)';
testbtn.style.marginLeft = '10px';
testbtn.style.backgroundColor = '#28a745';
testbtn.style.color = 'white';
testbtn.style.border = '1px';
testbtn.style.padding = '8px 12px';
testbtn.style.cursor = 'pointer';

// Button click event handler
testbtn.onclick = async function() {
  if (!window.confirm('Are you sure you want to submit all "Applicant By" records for Manager approval?')) {
    return;
  }

  var records = event.records;
  if (!records || records.length === 0) {
    alert('No records found.');
    return;
  }

  // Filter records where the Status is "Applicant By"
  var filteredRecords = records.filter(function(record) {
    return record.Status && record.Status.value === "Applicant By";
  });

  if (filteredRecords.length === 0) {
    alert('No records with status "Applicant By" found.');
    return;
  }

  var assigneeUserCode = 'thanakorn.k'; // Change to the actual login name or group name

  // Prepare the workflow actions for submission
  var workflowActions = filteredRecords.map(function(record) {
    return {
      id: record.$id.value,
      action: 'Submit',
      assignee: assigneeUserCode
    };
  });

  try {
    // API call to submit the records for approval
    console.log(kintone.api.url('/k/v1/records/status', true));
    console.log("Workflow Actions Payload:", JSON.stringify(workflowActions, null, 2));

    var response = await kintone.api(kintone.api.url('/k/v1/records/status', true), 'PUT', {
      app: kintone.app.getId(),
      records: workflowActions
    });

    alert(`Successfully submitted ${workflowActions.length} "Applicant By" records for Manager approval.`);
  } catch (error) {
    console.error('API Error:', error);
    alert('Error submitting records. Check the console for details.');
  }
};

// Add the button to the header menu space
kintone.app.getHeaderMenuSpaceElement().appendChild(testbtn);

});
})();

2 Likes