DEV Community

Tushar Raina
Tushar Raina

Posted on

2

How to update data of child table in web form using client script in Frappe Framework

how can I use the same client script which is basically updating the value of rows in the child table from the data coming from an external API and is working for the doctype form to work with the web form client script? the data is coming but the rows are not updating

The Script:

function updateCateringLimits(frm, responseMessage) {
   frappe.call({
      method: 'frappe.wis.doctype.script.get_catering_limits',
      args: {
         buid: frm.doc.buid,
         office_guid: responseMessage[frm.doc.officename]
      },
      callback: function (response) {
         const cateringLimitsObj = response.message;
         const cateringLimits = Object.values(cateringLimitsObj)[0];
         const childTable = frm.doc.catering_limits || [];

         // Clear the child table first
         while (childTable.length) {
            frm.get_field('cateringlimits').grid.remove_row(0);
         }

         // Add the new rows to the child table
         const childTableField = frm.fields_dict['cateringlimits'];
         if (childTableField && childTableField.grid) {
            cateringLimits.forEach(cateringLimit => {
               const newRow = frm.add_child('cateringlimits');
               newRow.minpeople = cateringLimit.minPeople;
               newRow.maxpeople = cateringLimit.maxPeople;
               newRow.cutoff = cateringLimit.cutoffHrs;
            });
         }

         // Refresh the form to show the updated child table
         frm.refresh_field('cateringlimits');
      }
   });
}
Enter fullscreen mode Exit fullscreen mode

I am trying to update my doctype script which is updating the rows of child table in doctype form but the script in not working in the web form client script i have tried to make changes and the code is working till wher it is able to fetch the data from the api but the grid is not updating

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay