Yonyx Functions enable you to perform calculations using values stored in placeholders as inputs. In this article, we will take a closer look at how an author can use these functions to determine the warranty eligibility of a product based on its purchase date.
For the purpose of this example, we will assume that a product is considered under warranty if it was purchased within the last 90 days.
To implement this, we will:
- Need to capture the purchase data in a placeholder.
- Calculate the number of days between the purchase date and today’s date.
- Based on whether this duration is more than 90 days or 90 days or less, automatically guide the user down the appropriate path.
Step 1: Capture the purchase date in a placeholder
- Create a Placeholder called purchase-date and another one called duration.
- Click on the blue gear drop-down after logging into Yonyx.
- Choose “User Defined Objects”
- Click on +Placeholder button.
- Enter placeholder name “Purchase Date”.
- Note, the platform automatically creates an internal name purchase-date.
- Click Save.
- Click on +Placeholder button.
- Enter placeholder name “Duration”
- Click Save.
- Now let us Create a Command called capture-purchase-date. A Yonyx command is a configurable form that can be embedded in any guidance step of a Yonyx guide.
- Under “User Defined Objects”, click on the Commands tab.
- Click on +Command button.
- Enter Command name as “Capture Purchase Date”.
- Note, the platform automatically creates an internal name capture-purchase-date.
- Enter a brief description in the mandatory description field, “A form to capture purchase date”
- Click on “Data Capture” tab.
- Click on “Add Field” button and choose “Date” option.
- The left panel helps you configure the form, while the right panel displays a preview of the form.
- Click on the Name field and type “purchase-date” to find the placeholder that will store the user’s input for this data capture element.
- Now enter Label Text, “Enter product purchase date” and click on the Save button.
- Now let us create a Yonyx guide and embed the command “capture-purchase-date” in its root node.
- Create a Yonyx Guide
- Click on the blue gear drop-down after logging into Yonyx.
- Choose “My Guides”
- Click on +Guide to start creating a Yonyx guide.
- Change the Title to, “Product Warranty Check”
- Clear the body section.
- Change follow-on question to “Next Step”
- Change First Response to “Continue”
- Remove Second Response
- Click Next
- Click Save & Edit
- Embed form “capture-purchase-date” in the root guidance step.
- Edit the root guidance step
- Scroll down in the right hand panel and click Choose under Command/Form
- Select “capture-purchase-date” command and click Insert.
- Note the form is now associated with the guidance step.
- Click Save
- The form now appears in the body section of the root guidance step.
- This form is not visible from the “Edit” view of the guidance step.
- Create a Yonyx Guide
Step 2: Using Yonyx Functions, calculate days between purchase date and today.
- Add Guidance Step
- Click on Continue.
- Click on “Add Step” button.
- Add title, “Calculate Duration”
- Add Follow-on question, “What duration?”
- Now let us add a function to calculate duration, to this guidance step.
- Add a Yonyx function called “Duration”
- Scroll down all the way in the right hand panel and click on Functions
- Clcik on “Click to pick function”
- Choose Date functions from the drop-down.
- Choose Duration function.
- Click Insert. Now let us configure this function.
- Scroll down and click on Value/Placeholder field for date1
- Configure the Yonyx function
- Click on User defined tab in Placeholder Explorer window to choose “purchase-date” placeholder.
- Click on Value/Placeholder field for date2
- Click on System tab in Placeholder Explorer window to choose “sys-ynx-date” placeholder. This system placeholder provides today’s date.
- Click on Value/Placeholder field for days under Output parameters
- Choose placeholder, “duration”.
- Click Save
Step 3: Automatically direct user along a path based on duration.
- Add Response “Greater than 90 days”
- Click “Add Response” button.
- Add “Greater than 90 days” in the body section.
- Scroll down all the way on the right hand panel.
- Click in the left hand text box under Placeholder Auto-traversal
- Choose duration from the User defined tab in the Placeholder Explorer window.
- Click on the condition drop-down and choose “Is Greater Than”
- Click on the right hand box and enter the value, 90.
- Save
- Add Guidance Step “Not Under Warranty”
- Click “Add Step” button.
- Enter Title, “Not Under Warranty”
- In the body section, enter text, Your product was purchased on {{ph:purchase-date}}, which is {{ph:duration}} days ago. Since it’s been more than 90 days, the product is not covered under warranty.
- Note you can insert placeholders within body section to display placeholder values using the syntax above. You can also insert placeholders by clicking on Tools->Insert Placeholder and then choosing the placeholder whose value you want to display.
- Add Response “Less than or equal to 90 days”
- Click on the Guidance step, “Calculate Duration”
- Click “Add Response” button.
- Add “Less than or equal to 90 days” in the body section.
- Scroll down all the way on the right hand panel.
- Click on the checkbox, “Fallback Auto Traversal” at the bottom of the screen. It means the auto-traverse condition set for “Greater than 90 days” is not met, then this User Response will be picked for auto traversal.
- Save
- Add Guidance Step “Under Warranty”
You can now test this guide by clicking on View under the guide name, from My Guides. Note, the auto-traverse conditions cause the guide to automatically skip along one of the two leaf guidance steps. When a user reaches a Yonyx guidance step in User View, the following sequence is executed:
- Placeholders are set – Any user-defined placeholders that have been explicitly assigned a value within the guidance step are updated with those specified values.
- Functions are executed – Functions run in the top to bottom order.
- Body content is displayed – The body of the step is processed. If placeholders appear within the step, their values—computed by Yonyx Functions within the same step—are displayed.