HD Form Script Not Working

HD Form Script Not Working

Script

function setupForm({
  doc,
  updateField,
  call,
  router,
  $dialog,
  createToast,
}) {
  const actions = [
    {
      group: "Actions",
      hideLabel: true,
      items: [
        {
          label: "Open FC Info",
          onClick: () => {
            // Call API to get custom information
            call("show_custom_info", {
              ticket: doc.name,
              // Include relevant fields for fetching data
            }).then((data) => {
              if (data.name) {
                $dialog({
                  title: data?.title,
                  message: data?.message,
                  html: data?.html, // this field can be in HTML format
                  actions: [
                    {
                      label: "Open in FC",
                      variant: "solid",
                      onClick(close) {
                        let URL = `http://helpdesk:8010/app/hd-ticket/${doc?.name}`;
                        window.open(URL, "_blank");
                      },
                    },
                    //   add more actions
                  ],
                });
              }
            });
          },
        },
        {
          label: "Close this ticket",
          onClick: () => {
            $dialog({
              title: "Close this ticket?",
              message: "Are you sure you want to mark this close this ticket?",
              actions: [
                {
                  label: "Close",
                  theme: "red",
                  variant: "solid",
                  onClick(close) {
                    updateField("status", "Closed", () => {
                      createToast({
                        title: "Ticket has been closed",
                        icon: "alert-circle",
                      });
                      close();
                    });
                  },
                },
                {
                  label: "Cancel",
                  variant: "outline",
                  onClick(close) {
                    close();
                  },
                },
              ],
            });
          },
        },
      ],
    },
  ];
  if (doc.status !== "Closed") {
    actions.push({
      label: "Close the ticket",
      onClick: () => {
        $dialog({
          title: `Close ticket: ${doc.name}`,
          message: "Are you sure you want to close this ticket?",
          actions: [
            {
              label: "Close",
              theme: "red",
              variant: "solid",
              onClick(close) {
                updateField("status", "Closed", () => {});
                close();
              },
            },
            {
              label: "Cancel",
              variant: "outline",
              onClick(close) {
                close();
              },
            },
          ],
        });
      },
    });
  }

  return {
    actions,
  };
}

Issue:

Frappe Cloud

Frappe Framework Version

frappe: 16.31.0 (HEAD)

Installed Apps

ERPNext

erpnext: 16.32.3 (HEAD)

Telephony

telephony: 0.0.1 (HEAD)

Helpdesk

helpdesk: 1.29.0 (HEAD)

I think the issue is that this is using the Frappe CRM form-script API, while HD Ticket in Helpdesk has its own form scripting structure.

I’d first test with a very simple action to confirm the script is being loaded:

function setupForm({ doc }) {
  return {
    actions: [
      {
        label: "Test Action",
        onClick() {
          console.log("HD Ticket script loaded", doc.name);
        },
      },
    ],
  };
}

If this doesn’t appear, the problem is likely with where/how the script is configured rather than the code itself.

Also, http://helpdesk:8010 may not be accessible from the browser if helpdesk is only a Docker hostname.

2 Likes

Hi @Usman-Kanz for HD Form scripts please refer to this documentation for proper set of actions and guide in setting up custom actions

I would also like to know if you are facing any errors while having enable the script and the page running? please check your browser and error log.