You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在OneClick规则中对字段当前值进行加减操作?

How to Adjust Remaining/Completed Time by 6-Hour Offsets in OneClick Rules

Hey Vijay, I’ve dealt with this exact headache in OneClick rule config before—let me break down the two reliable ways to adjust those time fields by a 6-hour offset without hardcoding values:

1. Use OneClick’s Built-in Expression Editor (Simplest Method)

Most modern OneClick versions include an expression mode for field modifications that lets you reference the current value of a field:

  • Navigate to your rule’s Field Update section, then select the Remaining Time field you want to modify.
  • Look for an fx or Expression Mode toggle (usually next to the value input box) to switch away from static value entry.
  • Enter the expression to subtract 6 hours (note: most time fields in OneClick store values in seconds, so 6 hours = 21600 seconds):
    {{current_value}} - 21600
    
  • Repeat this for the Completed Time field, using the addition expression instead:
    {{current_value}} + 21600
    
  • Save your rule and trigger a test event to verify the time fields update correctly.

2. Use a Custom Script Action (For Advanced Cases)

If your OneClick version doesn’t support expression mode, or if you need more control over date parsing, add a script action to your rule workflow:

  • Add a Script Step to your rule (OneClick typically supports Python or JavaScript for custom scripts).
  • Use a script like this (example in Python, assuming OneClick exposes the target entity as entity):
    from datetime import datetime, timedelta
    
    # Adjust Remaining Time: subtract 6 hours
    if isinstance(entity['remaining_time'], int):
        # If stored in seconds
        entity['remaining_time'] -= 21600
    else:
        # If stored as ISO datetime string
        remaining_dt = datetime.fromisoformat(entity['remaining_time'])
        entity['remaining_time'] = (remaining_dt - timedelta(hours=6)).isoformat()
    
    # Adjust Completed Time: add 6 hours
    if isinstance(entity['completed_time'], int):
        entity['completed_time'] += 21600
    else:
        completed_dt = datetime.fromisoformat(entity['completed_time'])
        entity['completed_time'] = (completed_dt + timedelta(hours=6)).isoformat()
    
    # Save the updated entity
    entity.save()
    
  • Ensure your script has permission to modify these fields, then position this step before the rule’s save action.

Quick Notes to Avoid Mistakes

  • Double-check the time unit your OneClick instance uses: some older versions store time in milliseconds instead of seconds (multiply 21600 by 1000 if that’s the case).
  • If your time fields use a non-standard format, use OneClick’s built-in date utilities (if available) instead of custom parsing to avoid errors.

内容的提问来源于stack exchange,提问作者Vijay Nirmal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:43:06