frappe.listviewsettings['HD Ticket'] = { addfields: ['priority', 'status'],…
- User
frappe.listview_settings['HD Ticket'] = { add_fields: ['priority', 'status'], get_indicator: function (doc) { switch (doc.status) { case "Open": return [("Open"), "red", "status,=,Open"]; case "In Progress": return [("In Progress"), "orange", "status,=,In Progress"]; case "On Hold": return [("On Hold"), "yellow", "status,=,On Hold"]; case "Resolved": return [("Resolved"), "blue", "status,=,Resolved"]; case "Closed": return [("Closed"), "green", "status,=,Closed"]; default: return [(doc.status), "gray", "status,=," + doc.status]; } } };
this only shows colour for open only , rest do not have any clour
- Assistant
Okay, the code you've provided looks syntactically correct for defining list view indicators in Frappe. The issue where only "Open" shows a color, and the others don't, usually points to one of these problems:
- Data Mismatch: The actual values stored in the
statusfield for your 'HD Ticket' DocType might not exactly match the strings in yourcasestatements (e.g., "In Progress" vs "in progress", or "On Hold" vs "On Hold "). Case sensitivity matters. - Field Name: Ensure the field is actually named
statusin your 'HD Ticket' DocType. Sometimes it might be named differently (likestate,workflow_state, etc.). - JavaScript Loading/Execution: The Javascript file containing this code might not be loading correctly, or another script might be interfering.
- Caching: Frappe caches Javascript. Sometimes a hard refresh is needed.
Troubleshooting Steps & Refined Code:
-
Verify Data & Field Name:
- Go to the list view of 'HD Ticket'.
- Open the Awesome Bar (Ctrl+Space or Cmd+Space).
- Type
DocType: HD Ticketand select it. - Find a ticket that should be "In Progress" or "Resolved" but isn't showing the correct color.
- Type
/{your_ticket_name}(e.g.,HDT-0001) in the Awesome Bar and press Enter to open the ticket document itself. - Check the
statusfield (or whatever the actual field name is) in the form view. Note the exact value, including capitalization and any leading/trailing spaces. - If the field name is different, update your
get_indicatorfunction accordingly. - If the values are different (e.g., lowercase), update your
casestatements to match.
-
Refined Code (Assuming
statusis the correct field name): This version uses the actualdoc.statusfor the label, which can sometimes be more reliable if the translation keys (__("...")) aren't perfectly mapped or if you want the label to exactly match the data value.frappe.listview_settings['HD Ticket'] = { add_fields: ['priority', 'status'], // Ensure 'status' is the correct field name get_indicator: function (doc) { // Ensure the field name 'status' is correct for your DocType var status = doc.status; if (!status) { // Handle cases where status might be missing return [__("No Status"), "gray", "status,=,"]; } // Use lowercase comparison for robustness if needed, but stick to exact match first var status_lower = status.toLowerCase(); switch (status) { case "Open": // Label: __("Open"), Color: red, Filter: status equals Open return [__("Open"), "red", "status,=,Open"]; case "In Progress": // Label: __("In Progress"), Color: orange, Filter: status equals In Progress return [__("In Progress"), "orange", "status,=,In Progress"]; case "On Hold": // Label: __("On Hold"), Color: yellow, Filter: status equals On Hold return [__("On Hold"), "yellow", "status,=,On Hold"]; case "Resolved": // Label: __("Resolved"), Color: blue, Filter: status equals Resolved return [__("Resolved"), "blue", "status,=,Resolved"]; case "Closed": // Label: __("Closed"), Color: green, Filter: status equals Closed return [__("Closed"), "green", "status,=,Closed"]; default: // Fallback for any other status value // Use the actual status value for the label, translated // Color is gray, Filter uses the actual status value return [__(status), "gray", "status,=," + encodeURIComponent(status)]; } } };Key changes/notes:
- Added comments emphasizing checking the field name and data values.
- Added a check for
!status. - Used
encodeURIComponentin the default filter's value, which is good practice if status values might contain special characters, although unlikely for simple status strings.
-
Clear Cache & Reload:
- After saving the
.jsfile (usually in your app'spublic/js/folder or relevant*.bundle.jsfile), clear your Frappe cache:- Go to
[your-erpnext-site]/app/(or just refresh the page if logged in). - Alternatively, run
bench --site [your-site-name] clear-cachein your terminal.
- Go to
- Do a hard refresh in your browser (Ctrl+Shift+R or Cmd+Shift+R).
- After saving the
By checking the exact data values and ensuring the field name is correct, you should be able to get all the indicators working as intended.
- Data Mismatch: The actual values stored in the
- User
Open In Progress On Hold Resolved Closed
- Assistant
Okay, thank you for confirming the specific status values you are using. This list aligns perfectly with the
casestatements in your original JavaScript code.Since "Open" is working correctly, it strongly suggests:
- The JavaScript code is loading and executing.
- The field is indeed named
status. - The indicator logic itself is fundamentally sound.
The most probable reason why only "Open" shows a color and the others don't is a mismatch between the exact string value stored in the
doc.statusfield and the string literal used in thecasestatement for the other statuses.Here's the detailed troubleshooting process:
-
Inspect the Actual Data:
- Go to the 'HD Ticket' list view in Frappe/ERPNext.
- Find a ticket that should be showing an indicator for "In Progress", "On Hold", "Resolved", or "Closed" but isn't.
- Open that specific ticket in the Form View.
- Carefully look at the
statusfield in the form. Pay extremely close attention to:- Case: Is it exactly "In Progress" or perhaps "in progress" or "IN PROGRESS"?
- Spaces: Are there any leading or trailing spaces (e.g., " Resolved " instead of "Resolved")?
- Spelling: Double-check the spelling.
-
Compare with Your Code: Compare the exact value you found in the form view with the strings in your
get_indicatorfunction:case "In Progress":case "On Hold":case "Resolved":case "Closed":
-
Adjust the Code (if necessary): If you find a mismatch, you have two options:
- (Recommended for Consistency): Adjust your JavaScript code to match the actual data values stored in your system. For example, if the status is stored as
"in progress"(lowercase), change your code to:
Important: Make sure the value in the filter condition (case "in progress": // <-- Changed to match data return [__("In Progress"), "orange", "status,=,in progress"]; // <-- Also update filter value"status,=,...") also matches the actual data value. - (Less Common): Update the actual data in your 'HD Ticket' records to match the code. This is usually more work if you have many records.
- (Recommended for Consistency): Adjust your JavaScript code to match the actual data values stored in your system. For example, if the status is stored as
-
Clear Cache and Refresh:
- After saving any changes to your
.jsfile (ensure it's saved in the correct location, likeyour_app/your_app/public/js/hd_ticket_listview.jsor similar, and potentially bundled), always clear the Frappe cache:- Run
bench --site [your-site-name] clear-cachein your terminal.
- Run
- Perform a hard refresh in your browser (Ctrl+Shift+R or Cmd+Shift+R) to ensure you're loading the updated JavaScript.
- After saving any changes to your
Example Scenario:
If you inspect a ticket and find the status is actually stored as
"On hold"(lowercase 'h'), you would need to change your code from:case "On Hold": return [__("On Hold"), "yellow", "status,=,On Hold"];to:
case "On hold": // <-- Match the actual data return [__("On hold"), "yellow", "status,=,On hold"]; // <-- Update label and filter value if needed(Note: It's often better to use consistent casing like "Open", "InProgress", "OnHold", "Resolved", "Closed" in your data and code to avoid these issues).
Start by carefully inspecting the data for one of the non-working statuses, and that should reveal the exact discrepancy.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.