一、數(shù)據(jù)更新事件-函數(shù)編寫(xiě)模板:
(1)在新建/編輯頁(yè),當(dāng)某一字段修改(值改變且失焦)時(shí),觸發(fā)自定義函數(shù)來(lái)更新主對(duì)象或從對(duì)象的數(shù)據(jù)
Groovy:
// 獲取當(dāng)前頁(yè)面標(biāo)識(shí) Add:新建頁(yè)面,Edit:編輯頁(yè)面
context.actionPage
//新建UIEvent事件
UIEvent event = UIEvent.build(context) {
//把字段設(shè)置為只讀、隱藏、必填
editMasterFields "field_I18ri__c" readOnly(true) hidden(true) required(true)
//設(shè)置提醒消息
remind Remind.Text("感嘆號(hào)提醒")
//設(shè)置提醒消息
remind Remind.Alert("彈窗提醒")
//主對(duì)象修改數(shù)據(jù)
editMaster("name": "test", "b": 2)
//是否自動(dòng)計(jì)算主對(duì)象和從對(duì)象的計(jì)算字段和默認(rèn)值
doCalculate(true)
//添加一條從對(duì)象,添加從對(duì)象,必須指定業(yè)務(wù)類型,而且是當(dāng)前布局展示的業(yè)務(wù)類型
//如果業(yè)務(wù)類型不匹配.從對(duì)象無(wú)法添加
addDetail "detailApiName" set("record_type": "default__c", "name": "demo001")
//根據(jù)條件刪除 從對(duì)象, 刪除為where中返回為true的從對(duì)象
removeDetail "detailApiName" where { x -> (x["a"] as Integer) > 0 }
//根據(jù)條件編輯從對(duì)象 和上同理只會(huì)處理where 中返回為true的從對(duì)象數(shù)據(jù)
editDetail "detailApiName" set("a": 1, "b": 2) where { x -> (x["a"] as Integer) > 0 }
//removeDetail和editDetail 都可以不添加where這樣會(huì)直接作用于所有數(shù)據(jù)
//set的內(nèi)容和editMaster的內(nèi)容要保證是map也就是key:valued的形式
removeDetail "detailApiName"
editDetail "detailApiName" set("a": 1, "b": 2)
// 將apiName為object_0uyAd__c的從對(duì)象隱藏 (注:從對(duì)象隱藏后,保存數(shù)據(jù)時(shí)會(huì)將隱藏的從對(duì)象數(shù)據(jù)清空,切記謹(jǐn)慎使用,可通過(guò)keepData來(lái)自定義是否保留數(shù)據(jù)。默認(rèn)為false)
editObject 'object_0uyAd__c' hidden(true) keepData(true) // keepData默認(rèn)為false
// 從對(duì)象隱藏業(yè)務(wù)類型
editDetailRecordType "object_qep6N__c" recordType("defaultA__c") hidden(true)
// 選項(xiàng)值隱藏
editOption "object_qep6N__c" fieldApiName("field_y210t__c") option("wwxJqgnO4") hidden(true)
// 隱藏批量編輯按鈕field_y1XV1__c
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.BATCH_UPDATE, true)
// 隱藏批量刪除按鈕
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.BATCH_DELETE, true)
// 隱藏批量復(fù)制按鈕
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.BATCH_CLONE, true)
// 隱藏通用添加一行按鈕
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.SINGLE_ADD_ONE, true)
// 隱藏通用按鈕--從對(duì)象查找關(guān)聯(lián)
editDetailButton "object_qep6N__c" recordType("defaultA__c") lookupFieldApiName("field_y1XV1__c") hiddenButton(ButtonAction.BATCH_LOOKUP_CREATE, true)
// 隱藏單條刪除操作
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.SINGLE_DELETE, true) where { x -> (x["a"] as Integer) > 0 }
// 隱藏單條復(fù)制操作
editDetailButton "object_qep6N__c" recordType("defaultA__c") hiddenButton(ButtonAction.SINGLE_CLONE, true) where { x -> (x["a"] as Integer) > 0 }
// 從對(duì)象字段只讀隱藏支持單條 (無(wú)where條件時(shí)表示所有數(shù)據(jù)隱藏、只讀、必填)
editDetailFields "object_qep6N__c" fieldApiName("field_jt9F4__c") hidden(true) readOnly(true) required(true) where { x -> (x["a"] as Integer) > 0 }
editDetailFields "object_qep6N__c" fieldApiName("field_y220t__c") hidden(true) readOnly(true) required(true) where { x -> (x["a"] as Integer) > 0 }
//獲取被刪除的從對(duì)象方式一
if (context.arg != null) {
def deletedDetails = (context.arg as Map)["deletedDetails"] as Map
}
//獲取被刪除的從對(duì)象方式二
Map currentDeletedDetail = event.getCurrentDeletedDetail()
}
return event
Copied!
(2)在主從同時(shí)新建/編輯頁(yè),當(dāng)新建/編輯/刪除從對(duì)象時(shí),觸發(fā)自定義函數(shù)來(lái)更新主對(duì)象/從對(duì)象的數(shù)據(jù)
Groovy:
UIEvent event = UIEvent.build(context) {
//主對(duì)象、從對(duì)象數(shù)據(jù)修改,詳見(jiàn)上
}
//獲取當(dāng)前操作的從對(duì)象數(shù)據(jù)
Map currentData = event.getCurrentDetail()
//修改當(dāng)前操作的從對(duì)象數(shù)據(jù)(主要用于新建明細(xì)和編輯明細(xì)的場(chǎng)景下)
currentData.put("從對(duì)象字段的ApiName","該字段需要變更的值為")
currentData.put("從對(duì)象字段1的ApiName","該字段1需要變更的值為")
//獲取當(dāng)前新增的從對(duì)象數(shù)據(jù)
List currentData = event.getCurrentAddDetail()
//獲取當(dāng)前批量操作的從對(duì)象數(shù)據(jù)(兼容單條)
Map currentBatchDetails = event.getCurrentBatchDetails();
return event
Copied!
(3)返回錯(cuò)誤信息到頁(yè)面示例:
Fx.message.throwErrorMessage("錯(cuò)誤信息");
return null;
Copied!
二、頁(yè)面加載事件-函數(shù)編寫(xiě)模板:
參考數(shù)據(jù)更新事件
三、校驗(yàn)事件-函數(shù)編寫(xiě)模板:
Groovy:
//紅字提醒
Remind remind = Remind.Text("Text");
//彈窗提醒
Remind remind = Remind.Alert("Text");
//設(shè)置提醒消息
remind Remind.builder()
.remindText("name", "主屬性名稱重復(fù)")
.remindText("field_y2k46__c", "字段不能包含test")
.build()
//清除提醒消息
remind Remind.builder()
.remindText("name", "")
.remindText("field_y2k46__c", "")
.build()
return remind;