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
- string standalone.createtradeinvoicesa(String orderId,String userId,String invType)
- {
- // earlier code creates invMap with invoice items
- // CREATE NEW INVOICE IN ZOHO BOOKS
- resp = zoho.books.createRecord("Invoices",orgId,invMap,"zbooksall");
- if(resp.get("code") == 0)
- {
- //for client script
- invoiceid = resp.get("invoice").get("id");
- invoiceinfo = zoho.books.getRecordsByID("invoices",orgId,invoiceid,"zbooksall");
- info "client-script-output=" + invoiceinfo;
- invoiceNum = resp.get("invoice").get("invoice_number");
- invoiceDate = today.toDate("dd/mm/yyyy");
- invoiceDate = invoiceDate.toString("dd/MM/yyyy");
- //user id and name for note
- else
- {
- returnMsg = "Error : an invoice has not been created in Zoho Books.";
- }
- return invoiceinfo;
- }
Client Script
- var functionName = "xxx";
- // get the order and user ID of this page
- var record_id = $Page.record_id;
- var user_id = $Crm.user.id;
- // get field values
- var stage_value = ZDK.Page.getField('Stage').getValue();
- var orderNo = ZDK.Page.getField('Deal_Name').getValue();
- // other checks go before this in the full script
- //If user clicks Proceed button
- if (isProceed) {
- // Message
- var successText = 'You will find your draft invoice in the Zoho Finance section below.';
- var errorText = 'There has been a problem, your invoice has not been created.';
- // show loader
- ZDK.Client.showLoader({ type: 'page', template: 'spinner', message: 'Creating Invoice...' });
- // call function in variable
- var response = ZDK.Apps.CRM.Functions.execute(functionName, { "orderId": record_id, "userId": user_id });
- ZDK.Client.hideLoader();
- // show sucess or error messages and execute function
- // response from function is the new invoice information, so in theory, the response should be null/undefined if the invoice wasn't created.
- if (response) {
- var sucessMessage = ZDK.Client.showAlert(successText, 'Invoice Created', 'Close');
- return response & successMessage & $Client.refresh();
- } else {
- errorMessage = ZDK.Client.showMessage(errorText, { type: 'error' });
- return errorMessage;
- }
- }
- //If user clicks Cancel button from invoice creation
- else {
- return false;
- }
Recent Topics
Ask the Experts #1
Hello everyone! It’s time to transform how you manage projects. Define the processes. Automate the tasks. Streamline the workflows. Let us dive into automation in Zoho Projects — from configuring workflows and custom functions to building triggers, using
How to overcome Zoho Deluge's time limit?
I have built a function according to the following scheme: pages = {1,2,3,4,5,6,7,8,9,10}; for each page in pages { entriesPerPage = zoho.crm.getRecords("Accounts",page,200); for each entry in entriesPerPage { … } } Unfortunately, we have too many entries
Checking if Creator has Change History
Like zForms - whenever an entry was updated there's an option to attached change history to email notif. Trigger -> Successful form submission
how to use validation rules in subform
Is it possible to use validation rules for subforms? I tried the following code: entityMap = crmAPIRequest.toMap().get("record"); sum = 0; direct_billing = entityMap.get("direct_billing_details"); response = Map(); for each i in direct_billing { if(i.get("type")
Adding contact role to a specific deal js sdk malfunctioning
i was trying to add the contact role to a specific deal contact but repeatedly i am getting this error: { "code": "SUCCESS", "details": { "statusMessage": { "code": "INVALID_DATA", "details": { "expected_data_type": "jsonobject" }, "message": "body",
Q3 Updates from Bigin!
Hey Biginners, Hope you’re doing great! As we approach the end of 2025, we truly hope Bigin has been a part of helping you build your dream business this year! We've been busy working behind the scenes to bring you features that make running your business
Client Script | Update - Introducing Subform Events and Actions
Are you making the most of your subforms in Zoho CRM? Do you wish you could automate subform interactions and enhance user experience effortlessly? What if you had Client APIs and events specifically designed for subforms? We are thrilled to introduce
{"errors":[{"id":"500","title":"Servlet execution threw an exception"}]}
Here's the call to move a file to trash. The resource_id is accurate and the file is present. header = Map(); header.put("Accept","application/vnd.api+json"); data = Map(); data_param1 = Map(); att_param1 = Map(); att_param1.put("status",51); data_param1.put("attributes",att_param1);
Converting Sales Order to Invoice via API; Problem with decimal places tax
We are having problems converting a Sales Order to an Invoice via API Call. The cause of the issue is, that the Tax value in a Sales Order is sometimes calculated with up to 16 decimal places (e.g. 0.8730000000000001). The max decimal places allowed in
Zoho Canvas - Custom templates for related lists
Hi, I see that the example pages load always one of our related lists in a custom template, but I dont know how to work with that: 1) How can i make my own custom templates for related lists? 2) Where and how can i check out existing custom templates?
Kaizen #147 - Frequently Asked Questions on Zoho CRM Widgets
Heya! It's Kaizen time again, folks! This week, we aim to address common queries about Zoho CRM Widgets through frequently asked questions from our developer forum. Take a quick glance at these FAQs and learn from your peers' inquiries. 1. Where can I
open word file in zoho writer desktop version
"How can I open a Microsoft Word (.doc or .docx) file in Zoho Writer if I only have the file saved on my computer and Zoho Writer doesn't appear as an option when I try 'Open with'? Is there a way to directly open the .doc file in Zoho Writer?"
Zoho PDF editor has a lot of issues.
Zoho PDF editor needs a lot of work. It hangs and glitches a lot. Deletes annotations and clearings randomly.
Syncing contacts on Android
I'm using the Zoho mail app on Android and although I can see my contacts from within the app, they're not synced to my native contact list and so I can't access them from within the native dialer. Is there any way that I can sync my contacts into my native address book? Regards, Martin
Zohom mail
Plz resolve the problem . I hope u understand .
Zoho sheet desktop version
Hi Zoho team Where can I access desktop version of zoho sheets? It is important as web version is slow and requires one to be online all the time to do even basic work. If it is available, please guide me to the same.
ZOHO SHEETS
Where can I access desktop version of zoho sheets? It is important to do basic work If it is available, please guide me to the same
Using Zoho Flow to create sales orders from won deal in Zoho CRM
Hi there, We are using Zoho Flow to create sales orders automatically when a deal is won in Zoho CRM. However, the sales order requires "Product Details" to be passed in "jsonobject", and is resulting in this error: Zoho CRM says "Invalid input for invalid
Is Zoho Sheet available for Linux ?
Is Zoho Sheet available for Linux ?
Bharat
a
how to disable staff selection Zoho Booking integrated to SalesIQ?
currently there is only one Consultant in my Zoho Bookings like this I integrate Zoho Bookings into Zoho SalesIQ to create a chatbot. Unfortunately, even though I only have one consultant for a consultation, the user have to pick the consultant. It will
Zoho Bookings No Sync with Outlook
Zoho Bookings appointments are showing on my Outlook Calendar but Outlook events are not showing on Zoho Bookings. How do I fix this?
End Date in Zoho Bookings
When I give my appointments a 30 minutes time I would expect the software not to even show the End Time. But it actually makes the user pick an End Time. Did I just miss a setting?
Custom confirmation message
How can I change the message that users see after they submit the booking form? I have to confirm some details before their appointment is officially "confirmed", so I want to change it where it doesn't say their appointment is "confirmed" but rather
Issue showing too many consultations in my workspace link.
Hi Team, I’ve set up two Workspaces to track meetings from different sources. So far, this has been working well, and the two Workspaces are differentiated without any issues. However, when I navigate to Consultations and share the link to my personal
Deluge sendmail in Zoho Desk schedule can't send email from a verified email address
I am trying to add a scheduled action with ZDesk using a Deluge function that sends a weekly email to specific ticket client contacts I've already verified the email address for use in ZDesk, but sendmail won't allow it in its "from:" clause. I've attached
unblock e-mail
please unblock my e-mails info@meatnews.gr and myrtokaterini@meatnews.gr
Changing Corporate Structure - How Best to Adapt Current and Future Zoho Instances
My current company is Company A LLC with a dba ("doing business as" - essentially an alias) Product Name B. Basically, Company A is the legal entity and Product Name B is what customers see, but it's all one business right now. We currently have a Zoho
How to Install Zoho Workdrive Desktop Sync for Ubuntu?
Hi. I am newbie to Linux / Ubuntu. I downloaded a tar.gz file from Workdrive for installing the Workdrive Desktop Sync tool. Can someone give me step by step guide on how to install this on Ubuntu? I am using Ubuntu 19.04. Regards Senthil
How to upload own video?
How can you upload your own video on your zoho website? I do not want to use another host, but i want to insert my own files. how can i do this?
Support new line in CRM Multiline text field display in Zoho Deluge
Hi brainstrust, We have a Zoho CRM field which is a Muti Line (Small) field. It has data in it that has a carriage return after each line: When I pull that data in via Deluge, it displays as: I'm hoping a way I can change it from: Freehand : ENABLED Chenille
Announcing new features in Trident for Windows (v.1.32.5.0)
Hello Community! Trident for Windows just got better! This update includes new features designed to improve and simplify email and calendar management—and it includes a feature you’ve been waiting for. Let’s dive into what’s new! Save emails in EML or
How to render either thumbnail_url or preview_url or preview_data_url
I get 401 Unauthorised when using these urls in the <img> tag src attribute. Guide me on how to use them!
Zoho CRM Calendar | Custom Buttons
I'm working with my sales team to make our scheduling process easier for our team. We primary rely on Zoho CRM calendar to organize our events for our sales team. I was wondering if there is a way to add custom button in the Calendar view on events/meeting
Create Lead Button in Zoho CRM Dashboard
Right now to create Leads in the CRM our team is going into the Lead module, selecting the "Create Lead" button, then building out the lead. Is there anyway to add the "Create Lead" button or some sort of short cut to the Zoho CRM Dashboard to cut out
Searching customer field
Hello, When entering a receipt, we select customer information. The customer information is synced with Zoho CRM. However, we can't find the customer information because it searches for words that begin with the entered value. It needs to search for words
Introducing Version-3 APIs - Explore New APIs & Enhancements
Happy to announce the release of Version 3 (V3) APIs with an easy to use interface, new APIs, and more examples to help you understand and access the APIs better. V3 APIs can be accessed through our new link, where you can explore our complete documentation,
Outgoing blocked: Unusual activity detected.
Hello i can't send email from g.morris@adm-part.com mail, can you please help me.
Zoho CRM Tracking Google Enhanced Conversions
Can anyone @Zoho, consultants, or users help me understand if Zoho CRM is going to support Google's Enhanced Conversions? I included some information from Google below about it. We use Google Adwords for our pay per click advertising for lead generation,
zoho click, and nord VPN
Unfortunately, we've been having problems with Zoho Click, where essentially the line cuts off after about a minute's worth of conversation every time we are on VPN. Is there a way we can change this within the settings so it does not cut the line off
Next Page