name: object_workflows
label: Object Synchronization Rule
icon: link
hidden: true
version: 2
fields:
  name:
    label: Name
    type: text
    required: true
    searchable: true
    filterable: true
  object_name:
    label: Object
    type: master_detail
    write_requires_master_read: true
    required: true
    reference_to: objects
    reference_to_field: name
    filters: [["enable_workflow", "=", true]]
    filterable: true
  flow_id:
    label: Workflow
    type: lookup
    required: true
    reference_to: flows
    filterable: true
  field_map:
    label: Field Mappings（from Object to Workflow）
    type: table
    is_wide: true
    depend_on:
      - object_name
      - flow_id
    amis:
      showIndex: true
      columns: ["workflow_field", "object_field"]
      enableDialog: false
  field_map.$.workflow_field:
    label: Field of Workflow
    type: lookup
    reference_to: object_fields
    reference_to_field: name
    enable_enhanced_lookup: false
    depend_on:
      - flow_id
    amis: 
      "autoComplete": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/api/object_workflows/workflow_field/options?flow_id=${flow_id}&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.flow_id"
      "source": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/api/object_workflows/workflow_field/options?flow_id=${flow_id}&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.flow_id"
  field_map.$.object_field:
    label: Field of Object
    type: lookup
    depend_on:
      - object_name
    reference_to: object_fields
    reference_to_field: name
    enable_enhanced_lookup: false
    defaultIcon: service_contract
    amis: 
      "autoComplete": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/options?include_deep=true&include_hide=true&include_related=true&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.object_name"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst options = [];\nfor (const item of data.options) {\n  if (item.value.startsWith('cms_files.') || item.value.startsWith('tasks.') || item.value.startsWith('notes.') || item.value.startsWith('events.') || item.value.startsWith('instances.') || item.value.startsWith('approvals.') || item.value.startsWith('process_instance_history.') || item.value.startsWith('audit_records.')) {\n    continue;\n  }\n  options.push(item);\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
      "source": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/options?include_deep=true&include_hide=true&include_related=true&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.object_name"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst options = [];\nfor (const item of data.options) {\n  if (item.value.startsWith('cms_files.') || item.value.startsWith('tasks.') || item.value.startsWith('notes.') || item.value.startsWith('events.') || item.value.startsWith('instances.') || item.value.startsWith('approvals.') || item.value.startsWith('process_instance_history.') || item.value.startsWith('audit_records.')) {\n    continue;\n  }\n  options.push(item);\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
  field_map_back:
    label: Field Mappings（from Workflow to Object）
    type: table
    is_wide: true
    depend_on:
      - object_name
      - flow_id
    amis:
      showIndex: true
      columns: ["object_field","workflow_field"]
      enableDialog: false
  field_map_back.$.object_field:
    label: Field of Object
    type: lookup
    depend_on:
      - object_name
    reference_to: object_fields
    reference_to_field: name
    enable_enhanced_lookup: false
    defaultIcon: service_contract
    amis: 
      "autoComplete": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/options?include_deep=true&include_hide=true&include_related=true&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.object_name"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst options = [];\nfor (const item of data.options) {\n  if (item.value.startsWith('cms_files.') || item.value.startsWith('tasks.') || item.value.startsWith('notes.') || item.value.startsWith('events.') || item.value.startsWith('instances.') || item.value.startsWith('approvals.') || item.value.startsWith('process_instance_history.') || item.value.startsWith('audit_records.')) {\n    continue;\n  }\n  options.push(item);\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
      "source": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/options?include_deep=true&include_hide=true&include_related=true&term=${term}"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.object_name"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst options = [];\nfor (const item of data.options) {\n  if (item.value.startsWith('cms_files.') || item.value.startsWith('tasks.') || item.value.startsWith('notes.') || item.value.startsWith('events.') || item.value.startsWith('instances.') || item.value.startsWith('approvals.') || item.value.startsWith('process_instance_history.') || item.value.startsWith('audit_records.')) {\n    continue;\n  }\n  options.push(item);\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
  field_map_back.$.workflow_field:
    label: Field of Workflow
    type: lookup
    reference_to: object_fields
    reference_to_field: name
    enable_enhanced_lookup: false
    depend_on:
      - flow_id
    amis: 
      "autoComplete": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/api/object_workflows/workflow_field/options?flow_id=${flow_id}&term=${term}&instance_fields=true"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.flow_id"
      "source": 
        "method": "get"
        "cache": 120000
        "url": "${context.rootUrl}/api/object_workflows/workflow_field/options?flow_id=${flow_id}&term=${term}&instance_fields=true"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}" 
        "sendOn": "!!this.flow_id"
  field_map_script:
    label: Synchronization Script（from Object to Workflow）
    type: textarea
    is_wide: true
    group: Script
  field_map_back_script:
    label: Synchronization Script（from Workflow to Object）
    type: textarea
    is_wide: true
    group: Script
  sync_attachment:
    label: Synchronization Mode of Attachment
    type: select
    options:
      - label: No Synchronization
        value: "null"
      - label: Synchronize the Latest Version
        value: lastest
      - label: Synchronize All Versions
        value: all
    required: true
  sync_type:
    label: Synchronization Mode
    type: select
    options:
      - label: Every Step
        value: "every_step"
      - label: Final Step
        value: "final_step"
    defaultValue: every_step
    required: true
  sync_direction:
    label: Synchronization Direction
    type: select
    options:
      - label: Both
        value: "both"
      - label: Instance To Object
        value: "ins_to_obj"
      - label: Object To Instance
        value: "obj_to_ins"
    defaultValue: both
    required: true
  lock_record_after_approval:
    label: Lock record after approval
    type: boolean
    defaultValue: false
    required: false
  required_details:
    label: Required Details
    inlineHelpText: Is There A Record Of The Sub Check Table When Initiating The Approval.
    type: select
    multiple: true
    is_wide: true
    depend_on:
      - object_name
    amis:
      disabledOn: "${is_system == true}"
      "source": 
        "method": "get"
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/relatedLists/options"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst needToRemove = ['cms_files.parent', 'tasks.related_to', 'notes.related_to', 'events.related_to', 'instances.record_ids', 'approvals.related_to', 'process_instance_history.target_object', 'audit_records.related_to'];\nconst options = [];\nfor (const item of data.options) {\n  if (!needToRemove.includes(item.value)) {\n    options.push(item);\n  }\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
        "sendOn": "this.object_name"
        "requestAdaptor": ""
      "autoComplete": 
        "method": "get"
        "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/relatedLists/options"
        "headers": 
          "Authorization": "Bearer ${context.tenantId},${context.authToken}"
        "adaptor": "let data = payload.data;\n// 移除 附件、任务、备忘、日程、审批单、历史步骤、批准步骤、审计日志\nconst needToRemove = ['cms_files.parent', 'tasks.related_to', 'notes.related_to', 'events.related_to', 'instances.record_ids', 'approvals.related_to', 'process_instance_history.target_object', 'audit_records.related_to'];\nconst options = [];\nfor (const item of data.options) {\n  if (!needToRemove.includes(item.value)) {\n    options.push(item);\n  }\n}\ndata.options = options;\npayload.data = data;\nreturn payload;\n"
        "sendOn": "this.object_name"
        "requestAdaptor": ""
    
list_views:
  default:
    columns:
      - name
      - object_name
      - flow_id
  all:
    columns:
      - name
      - object_name
      - flow_id
    label: All Rules
    filter_scope: space
  customize:
    columns:
      - name
      - object_name
      - flow_id
    label: 自定义
    filters:
      - ["is_system","<>",true]
    filter_scope: space
actions:
  forceSync:
    label: sync history approvals
    on: record
permission_set:
  user:
    allowCreate: false
    allowDelete: false
    allowEdit: false
    allowRead: true
    modifyAllRecords: false
    viewAllRecords: true
  admin:
    allowCreate: true
    allowDelete: true
    allowEdit: true
    allowRead: true
    modifyAllRecords: true
    viewAllRecords: true
