Using a CRM Client Script Button to create a Books Invoice

Using a CRM Client Script Button to create a Books Invoice

Hello,
I need help handling error messages returned to my client script from a function.

The scenario
I have setup a client script button which is available from each Deal.
This CS executes a crm function, which in turn creates an invoice based on the information in the Deal.
The client script checks the deal is at the correct stage and displays the amount to be invoiced, before proceeding to execute the function.

The problem
It all works perfectly well except for the error handling. I'm only testing for a 'response' from the function ( in the Client Script) before showing a success or error message, so even if the function returns null or undefined, it still says it has been successful.

What I tried
So, I wanted to pass something more useful to the client script, like the newly created invoice number or id but it just doesn't seem to be working. I have tried using variations of this approach:
var output = JSON.parse(response.details.output)
but get this error amongst others...
"undefined" is not valid JSON 
What doesn't help matters is that I can't fully test the invoice creation process, even using a crm sandbox, because it will still create real invoices in Books, which I would rather avoid.

What are your thoughts on how to approach this?  Below are the relevant parts of my code, in case it is useful to see.

CRM Function
  1. string standalone.createtradeinvoicesa(String orderId,String userId,String invType)
  2. {
  3. // earlier code creates invMap with invoice items
  4. // CREATE NEW INVOICE IN ZOHO BOOKS
  5. resp = zoho.books.createRecord("Invoices",orgId,invMap,"zbooksall");
  6. if(resp.get("code") == 0)
  7. {
  8. //for client script
  9. invoiceid = resp.get("invoice").get("id");
  10. invoiceinfo = zoho.books.getRecordsByID("invoices",orgId,invoiceid,"zbooksall");
  11. info "client-script-output=" + invoiceinfo;
  12. invoiceNum = resp.get("invoice").get("invoice_number");
  13. invoiceDate = today.toDate("dd/mm/yyyy");
  14. invoiceDate = invoiceDate.toString("dd/MM/yyyy");
  15. //user id and name for note
  16.    else
  17. {
  18. returnMsg = "Error : an invoice has not been created in Zoho Books.";
  19. }
  20. return invoiceinfo;
  21. }

Client Script

  1. var functionName = "xxx";
  2. // get the order and user ID of this page
  3. var record_id = $Page.record_id;
  4. var user_id = $Crm.user.id;
  5. // get field values
  6. var stage_value = ZDK.Page.getField('Stage').getValue();
  7. var orderNo = ZDK.Page.getField('Deal_Name').getValue();
  8. // other checks go before this in the full script
  9. //If user clicks Proceed button
  10. if (isProceed) {
  11. // Message
  12. var successText = 'You will find your draft invoice in the Zoho Finance section below.';
  13. var errorText = 'There has been a problem, your invoice has not been created.';
  14. // show loader
  15. ZDK.Client.showLoader({ type: 'page', template: 'spinner', message: 'Creating Invoice...' });
  16. // call function in variable
  17. var response = ZDK.Apps.CRM.Functions.execute(functionName, { "orderId": record_id, "userId": user_id });
  18. ZDK.Client.hideLoader();
  19. // show sucess or error messages and execute function
  20. // response from function is the new invoice information, so in theory, the response should be null/undefined if the invoice wasn't created.
  21. if (response) {
  22. var sucessMessage = ZDK.Client.showAlert(successText, 'Invoice Created', 'Close');
  23. return response & successMessage & $Client.refresh();
  24. } else {
  25. errorMessage = ZDK.Client.showMessage(errorText, { type: 'error' });
  26. return errorMessage;
  27. }
  28. }
  29. //If user clicks Cancel button from invoice creation
  30. else {
  31. return false;
  32. }

    • Sticky Posts

    • Kaizen #222 - Client Script Support for Notes Related List

      Hello everyone! Welcome to another week of Kaizen. The final Kaizen post of the year 2025 is here! With the new Client Script support for the Notes Related List, you can validate, enrich, and manage notes across modules. In this post, we’ll explore how
    • Kaizen #217 - Actions APIs : Tasks

      Welcome to another week of Kaizen! In last week's post we discussed Email Notifications APIs which act as the link between your Workflow automations and you. We have discussed how Zylker Cloud Services uses Email Notifications API in their custom dashboard.
    • Kaizen #216 - Actions APIs : Email Notifications

      Welcome to another week of Kaizen! For the last three weeks, we have been discussing Zylker's workflows. We successfully updated a dormant workflow, built a new one from the ground up and more. But our work is not finished—these automated processes are
    • Kaizen #152 - Client Script Support for the new Canvas Record Forms

      Hello everyone! Have you ever wanted to trigger actions on click of a canvas button, icon, or text mandatory forms in Create/Edit and Clone Pages? Have you ever wanted to control how elements behave on the new Canvas Record Forms? This can be achieved
    • Kaizen #142: How to Navigate to Another Page in Zoho CRM using Client Script

      Hello everyone! Welcome back to another exciting Kaizen post. In this post, let us see how you can you navigate to different Pages using Client Script. In this Kaizen post, Need to Navigate to different Pages Client Script ZDKs related to navigation A.

    Nederlandse Hulpbronnen


      • Recent Topics

      • Syncing with Google calendar, Tasks and Events

        Is it possible to sync Zoho CRM calendar, task and events with Google Calendar's tasks and events. With the increasing adoption by many major tool suppliers to sync seamlessly with Google's offerings (for instance I use the excellent Any.do task planning
      • Feature Request: Ability to set Default Custom Filters and apply them via URL/Deluge

        I've discovered a significant gap in how Zoho Creator handles Custom Filters for reports, and I'm hoping the Zoho team can address this in a future update. This limitation has been raised before and continues to be requested, but remains unresolved. The
      • filtering lookup field options based on information in another module.

        In our CRM system. We have the standard Accounts and Deals modules. We would like to introduce the ability to classify Accounts by Sector. Our desired functionality is to have a global list of all sectors that an Account can select, with the ability to
      • Really want the field "Company" in the activities module!

        Hi team! Something we are really missing is able to see the field Company when working in the activities module. We have a lot of tasks and need to see what company it's related to. It's really annoying to not be able to see it.🙈 Thx!
      • Cliq iOS can't see shared screen

        Hello, I had this morning a video call with a colleague. She is using Cliq Desktop MacOS and wanted to share her screen with me. I'm on iPad. I noticed, while she shared her screen, I could only see her video, but not the shared screen... Does Cliq iOS is able to display shared screen, or is it somewhere else to be found ? Regards
      • Service op locatie organiseren met Zoho FSM: waar lopen organisaties tegenaan?

        Bij organisaties met service teams op locatie merken we vaak dat de complexiteit niet zozeer in de planning zelf zit, maar in wat er rond die planning gebeurt. Denk aan opvolging na interventies, consistente servicerapporten, en het bijhouden van installaties
      • Workflow Down/Bug

        We have a workflow that sends an email to one of our internal departments 10 minutes after a record is created in a custom module. The workflow actually works correctly. However, we have now noticed that on January 8, between 3:55 p.m. and 4:33 p.m.,
      • Introducing Assemblies and Kits in Zoho Inventory

        Hello customers, We’re excited to share a major revamp to Zoho Inventory that brings both clarity and flexibility to your inventory management experience! Presenting Assemblies and Kits We’re thrilled to introduce Assemblies and Kits, which replaces the
      • Automate pushing Zoho CRM backups into Zoho WorkDrive

        Through our Zoho One subscription we have both Zoho CRM and Zoho WorkDrive. We have regular backups setup in Zoho CRM. Once the backup is created, we are notified. Since we want to keep these backups for more than 7 days, we manually download them. They
      • Does the ability exist to make tax on the customer profile mandatory?

        I am reaching out to inquire about the possibility of making the "Customer Tax" field mandatory when creating a new customer in Zoho. We want to ensure that all customers have their tax information recorded to maintain compliance with our internal processes.
      • CRM gets location smart with the all new Map View: visualize records, locate records within any radius, and more

        Hello all, We've introduced a new way to work with location data in Zoho CRM: the Map View. Instead of scrolling through endless lists, your records now appear as pins on a map. Built on top of the all-new address field and powered by Mappls (MapMyIndia),
      • How to apply customized Zoho Crm Home Page to all users?

        I have tried to study manuals and play with Zoho CRM but haven't found a way how to apply customized Zoho CRM Home Page as a (default) home page for other CRM users.. How that can be done, if possible? - kipi Moderation Update: Currently, each user has
      • Send Whatsapp with API including custom placeholders

        Is is possible to initiate a session on whatsapp IM channel with a template that includes params (placeholders) that are passed on the API call? This is very usefull to send a Utility message for a transactional notification including an order number
      • IMAP mail after specify date

        Hi My customer's mail server is on premise and mail storage is very huge. So It never finish sync. and finally stop sync. Cloud CRM have a option like zoho mail sync mail after some date.
      • email association with CRM

        Why is it 2024 (almost 2025) and Zoho has not figured out how to integrate email with CRM? It is so inconsistent at associating emails within CRM. I am an attorney. I have clients and work with other attorneys. Attorney John Doe is associated with multiple
      • Fix the speed

        It takes ages to load on every step even though my dataset is quite small.
      • Credit Note for Shipped and Fatoora pushed invoices

        We have shipped a Sales Order and created an Invoice. The Invoice is also pushed to Fatoora Now we need to create a credit note for the invoice When we try it, it says we need to create a Sales Return in the Zoho Books, we have already created a Sales
      • Whatsapp Connection Status still "Pending" after migration

        Hello, I migrated my WhatsApp API to Zoho from another provider a day ago. So far the connection status is still “Pending”. There is a problem? How long does it usually take?
      • FSM - Timesheet entires for Internal Work

        Hi FSM Team, Several of my clients have asked how they can manage internal timesheets within Zoho FSM. Since their technicians already spend most of their day working in FSM, it would be ideal if they could log all working hours directly in the FSM app.
      • Add a way of clearing fields values in Flow actions

        It would be great if there was an option to set a field as Null when creating flows. I had an instance today where I just wanted to clear a long integer field in the CRM based on an action in Projects but I had to write a custom function. It would be
      • Role Management

        I am creating an analytics dashboard for a company that will be utilized by its various departments such as Finance, Marketing, and HR. My goal is to design the dashboard with separate tabs for each department. Additionally, I plan to implement role-based
      • Link Contacts to Billed Accounts

        Hello, I want to do a survey on all my customers of 2025. For that I want to select all contacts linked to accounts who where billed in 2025. How to I create this link to I can then use Zoho Survey with this database of contacts?
      • Highlight a candidate who is "off limits"

        Hello: Is there a way to highlight a candidate who is "off limits"?  I would like to have the ability to make certain candidate and / or Client records highlighted in RED or something like that.   This would be used for example when we may have placed a candidate somewhere and we want everyone in our company to quickly and easily see that they are off limits.  The same would apply when we want to put a client or former client off limits so no one recruits out of there. How can this be done? Cheers,
      • Announcing new features in Trident for Windows (v.1.37.5.0)

        Hello Community! Trident for Windows just received a major update, with a range of capabilities that strengthen email security and enhance communication. This update focuses on making your mailbox safer and your overall email experience more reliable.
      • Early Payment Discount customize Text

        Hi, I’m currently using Zoho Books and am trying to customize the standard “Early Payment Discount” message that appears in the PDF invoice template. I’ve reviewed the documentation here: https://www.zoho.com/books/help/invoice/early-payment-discount.html
      • Automatic Matching from Bank Statements / Feeds

        Is it possible to have transactions from a feed or bank statement automatically match when certain criteria are met? My use case, which is pretty broadly applicable, is e-commerce transactions for merchant services accounts (clearing accounts). In these
      • Deprecation of SMS-based multi-factor authentication (MFA) mode

        Overview of SMS-based OTP MFA mode The SMS-based OTP MFA method involves the delivery of a one-time password to a user's mobile phone via SMS. The user receives the OTP on their mobile phone and enters it to sign into their account. SMS-based OTPs offer
      • How to Customize Task Creation to Send a Custom Alert Using JavaScript in Zoho CRM?

        Hello Zoho CRM Community, I’m looking to customize Zoho CRM to send a custom alert whenever a task is created. I understand that Zoho CRM supports client scripts using JavaScript, and I would like to leverage this feature to implement the alert functionality.
      • DKIM Now Mandatory - Changes to Zoho Forms Email Policies

        Hello Zoho Forms Users, This post is to inform you about an important update regarding the authentication of all email domains in your Zoho Forms account. This year, we are doubling down on our commitment to deliver a secure, seamless, and empowering
      • Ability to assign Invoice Ownership through Deluge in FSM

        Hi, As part of our process, when a service appointment is completed, we automated the creation of the invoice based on a specific business logic using Deluge. When we do that, the "Owner" of the invoice in Zoho FSM is defaulted to the SuperAdmin. This
      • Call description in notes

        When completing a call, we type in the result of the call in the description. However, that does not show up under the notes history on the contact. We want to be able to see all the calls that have taken place for a contact wihtout having to go into
      • Please can the open tasks be shown in each customer account at the top.

        Hi there This has happened before, where the open tasks are no longer visible at the top of the page for each customer in the CRM. They have gone missing previously and were reinstated when I asked so I think it's just after an update that this feature
      • Mapping a new Ticket in Zoho Desk to an Account or Deal in Zoho CRM manually

        Is there any way for me to map an existing ticket in Zoho desk to an account or Deal within Zoho CRM? Sometimes people use different email to put in a ticket than the one that we have in the CRM, but it's still the same person. We would like to be able
      • Email Address for Contact not Populating

        When I click "Send Mail" from a Contact's page, their email address does not auto populate the "To" field. How do I make this happen?
      • New in CRM: Dynamic filters for lookup fields

        Last modified on Oct 28, 2024: This feature was initially available only through Early Access upon request. It is now available to all users across all data centers, except for the IN DC. Users in the IN DC can temporarily request access using this form
      • Why hybrid project management might be the best fit for you?

        Project management techniques are designed to equip teams with proven methods for easy and efficient project execution. While management teams may have apprehensions about adopting the hybrid method of project management, we’ve compiled the top reasons
      • Allow all Company Users to view all projects, but only owner/admins can change projects

        I was wondering if there was a permission setting I could adjust to allow all our company users to see all projects created. Then, only the project owners and admins with the change permission. Thanks
      • Fail to send Email by deluge

        Hi, today I gonna update some email include details in deluge, while this msg pops up and restrict me to save but my rules has run for one year. I dont care why zoho suddenly add this useless limit, but can you tell me how to use one of our admin account
      • Seeking help to be able to search on all custom functions that are defined

        Hello I have a lot of custom functions defined (around 200) and i would like to search some specific strings in the content of those. Is there a way to accomplish that? If not, is there a way to download all existing custom functions in some files locally
      • Totals for Sales Tax Report

        On the sales tax report, the column totals aren't shown for any column other than Total Tax. I can't think of a good reason that they shouldn't be included for the other columns, as well. It would help me with my returns, for sure. It seems ludicrous
      • Next Page