Update an existing record using stateless forms

Update an existing record using stateless forms

Requirement  

Use details specified in a stateless form to modify records in the main form.

Use Case  

In an order management system, a customer has placed an order and wants to cancel it. The administrators allow for cancellation by accepting the reason and updating the same in the current record. However, the other fields cannot be updated. So, we get the values of the required fields for cancellation and update the main order record.

Steps to follow  

1. Create the forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
New Order
New_Order
Email
Contact Email
Contact_Email
Date
Order Date
Order_Date
Subform
  • Single Line
  • Number
  • Currency
  • Currency
Products
  • Product Name
  • Quantity
  • Rate
  • Sub-Total
Products
  • Product_Name
  • Quantity
  • Rate
  • Sub_Total
 
Currency
Total
Total
Drop Down
  • Pending
  • Ready to Deliver
  • Delivered
  • Cancelled
Order Status
Order_Status
Date
Cancellation Date
Cancellation_Date
Multi-line
Reason
Reason
Cancellation
Cancellation ( Duplicate this form to create a stateless form named Cancel Request )
Date ( Initial Value : zoho.currentdate )
Cancellation Date
Cancellation_Date
Number
Order ID
Order_ID
Multi-line
Reason (Mandatory)
 
Reason

Mark the
Order Status field as admin only We shall add the
  • Cancellation Date  
  • Reason fields
to the New Order form to a section named Cancellation.
 
2. Let's create a workflow to execute during the load of the New Order form to hide the Cancellation section.
 
3. Add the below code in the Deluge Editor:
  1. hide Cancellation; 

4. We will display Cancel Request form when the customer chooses to cancel an order placed. So, let's hide this form from sections.
 
5. Only the user who placed an order can cancel one. This is why we are creating a report to list only those orders created by the logged-in user. Create a list report from the New Order form and name it as Your Orders.
 
6. Add a filter to the Your Orders report to display only the orders for the current login user and active orders - with Order Status value Pending or Ready to Deliver or Delivered.
 
7. Next, let's add a report workflow to allow for the customers to cancel an order. Click on the My Orders report. Navigate to Quick View > Add Field > Add New Button. Name the Action Item as 'Cancel Order'.
 
8. An order can be cancelled if it is not delivered. So, set the criteria to show the action item if the Order Status value is not Delivered.
 
9. We shall execute this action item after confirmation. Add a confirmation message accordingly as below.
 
10. Name the workflow as 'cancelOrder' and click Create Workflow.
 
11. Click Add New Action > Deluge Script > Create your own. Add the below deluge code to open the stateless form Cancel Request in a popup window with the Order ID value equal to the current record ID. This is done to ensure the correct order is cancelled by the user.
  1. openUrl( "#Form:Cancel_Request?Order_ID=" + ID, "popup window", "height=300px,width=300px");

12. Click Create. This will create the action item.

Now that the report workflow is configured, let us configure the functioning of the Cancel Request stateless form.
 
13. Let's create a workflow on the load of the Cancel Request to disable the Cancellation Date and hide the Order ID fields so that they are not modified.
 
14. Click on Add New Action and add the below script to disable the Cancellation Date and hide the Order ID fields.
  1. disable Cancellation_Date;
  2. hide Order_ID; 

15. Once this Cancel Request form is filled and submitted, the corresponding New Order record should be updated too. W e shall create a workflow to execute when the Submit button is clicked on the Cancel Request form.
 
16. Click Add New Action > Deluge Script. Add the below Deluge Script in the editor:
  1. //Closing the Cancel Request stateless form popup
  2. openUrl("#Script:page.parent.refresh ","parent window");

  3. //Get the corresponding New Order record
  4. order = New_Order[ID == input.Order_ID];

  5. //Update the Reason field
  6. order.Reason=input.Reason;

  7. //Update the Cancellation Date field
  8. order.Cancellation_Date=input.Cancellation_Date;

  9. //Update the Order Status to Cancelled
  10. order.Order_Status = "Cancelled";

17. Additionally, we can create a report to show the cancelled orders alone too. Create a list report named Cancelled Orders from the New Order form.
 
18. Add a filter to the Your Orders report to display only the cancelled orders.

See how it works                

Points to Note  

  • Instead of a stateless form to get the necessary details, we can open the New Order record and disable or hide the other fields, as well. We can create a workflow and during the edit of a record, we can disable or hide all the other fields except Cancellation section like this:
 
And add the below code in Deluge editor:
  1. disable Contact_Email;
  2. disable Order_Date;
  3. disable Delivery_Date;
  4. disable Total;
  5. disable Taxes;
  6. disable Net_Total;
  7. disable Order_Status;

  8. //Hide the subform
  9. hide Products;

  10. //Show the cancellation section
  11. show Cancellation;