Purpose
Ensure each Item has a single “order link” that:
- Can be created/updated by Support Team
- Can be set once by everyone else, then becomes locked (cannot be changed or removed)
Field used:
- Fieldname:
custom_what_link_to_order_more
Scope
Applies to:
- Item Master data maintenance
- Purchasing / replenishment workflow
- Support Team data governance
SOP 1 — Add or Update the Amazon Link (Support Team)
Who can do this
✅ Users with role: Support Team
Steps
- Go to Stock → Item
- Search and open the Item
- Find field: What Link to Order More
- Paste the Amazon URL (recommended format):
https://www.amazon.com/dp/ASIN
- Click Save
- Use the Order on Amazon button (if enabled) to verify link opens correctly
Expected result
- Link is saved and clickable
- Support Team can edit again anytime
SOP 2 — Set Link One Time (Non-Support Users)
Who this is for
Warehouse users / staff who can edit Items but are not Support Team.
Steps
- Open Item
- If link field is empty:
- Paste the correct URL
- Click Save
- After saving, do not attempt to change/remove the link
Expected result
- First save works
- Second change will be blocked with message:
“This link can only be set once. Contact Support Team to modify it.”
SOP 3 — Admin Setup: Create the Field (One-Time Setup)
Steps
- Go to Settings → Customize Form
- Select DocType: Item
- Add a field (or confirm existing):
Field configuration
- Label: What Link to Order More
- Field Type: Data
- Options: URL
- Length: 500 (or higher)
- Fieldname:
custom_what_link_to_order_more
- Click Save
- Click Update
Expected result
- Field appears on Item form
- Long URLs allowed
- URL is clickable
SOP 4 — Admin Setup: “Order on Amazon” Button (Client Script)
Steps
- Go to Settings → Client Script → New
- Set:
- DocType: Item
- View: Form
- Enabled: ✅
- Paste:
frappe.ui.form.on('Item', {
refresh(frm) {
if (frm.doc.custom_what_link_to_order_more) {
frm.add_custom_button(__('Order on Amazon'), () => {
window.open(frm.doc.custom_what_link_to_order_more, '_blank');
}, __('Order'));
}
}
});
- Save
- Refresh an Item record
Expected result
- Button appears only when link exists
- Button opens link in a new tab
SOP 5 — Admin Setup: Enforce “Set Once” (Server Script, Sandbox-Safe)
Goal
- Support Team can edit anytime
- Everyone else: can set once, cannot change/remove after it’s set
Steps
- Go to Settings → Server Script → New
- Set:
- Script Type: DocType Event
- Reference DocType: Item
- DocType Event: Before Save (or Validate)
- Enabled: ✅
- Paste:
FIELDNAME = "custom_what_link_to_order_more"
ALLOWED_ROLE = "Support Team"
current_user = frappe.session.user
user_roles = frappe.get_all(
"Has Role",
filters={"parent": current_user},
pluck="role"
)
if ALLOWED_ROLE not in user_roles:
if not doc.is_new():
old_value = frappe.db.get_value("Item", doc.name, FIELDNAME) or ""
new_value = doc.get(FIELDNAME) or ""
if old_value and new_value != old_value:
frappe.throw(
"This link can only be set once. Contact Support Team to modify it."
)
- Save
Validation test
- As Support Team: edit link → allowed
- As non-Support: set link once → allowed
- As non-Support: try change/remove → blocked
SOP 6 — Troubleshooting
Issue A: “Method Not Allowed / Login to access”
Cause: session expired or permissions.
Fix:
- Log out/in
- Ensure you are using
/app - Confirm role permissions for Server Script/Client Script
Issue B: “AttributeError: module has no attribute has_role / get_roles”
Cause: restricted server script sandbox
Fix: use the Has Role query method (the SOP 5 script)
Issue C: Field still editable after save
Cause: server script disabled or wrong DocType event
Fix:
- Confirm Server Script is Enabled
- Confirm DocType = Item
- Confirm Event = Before Save or Validate
SOP 7 — Rollback / Undo Changes
Disable enforcement (keep script for later)
- Settings → Server Script → open script → uncheck Enabled → Save
Remove the button
- Disable or delete the Client Script for Item
Remove UI lock (if you ever set Read Only Depends On)
- Customize Form → Item → field → clear Read Only Depends On → Save/Update
Leave a Reply