![](/img/trans.png)
[英]Use client-side script to set Business Process Flow Stage on Opportunity in Dynamics CRM
[英]Set custom warning message in business process flow
我有一個具有“特殊”驗證的業務流程。 必須將3個步驟中的至少一個設置為“是”,才能繼續進行下一個階段。
這是我的舞台變更處理程序。
var subStageRequirements = new Array();
subStageRequirements.push({ stage: 0, fields: ['new_is_project_scope_defined_substage'] });
subStageRequirements.push({ stage: 1, fields: ['new_is_demo_1_substage', 'new_is_demo_2_substage', 'new_is_selection_srv_outlined_substage'] });
subStageRequirements.push({ stage: 2, fields: ['new_is_proposal_substage', 'new_is_negotiation_substage'] });
function onStageChange(context) {
var stage = context.getEventArgs().getStage();
var stageCategory = stage.getCategory().getValue();
var direction = context.getEventArgs().getDirection();
if (direction == "Next") {
//validate requirements on previous field...
var valid = false;
var req = subStageRequirements[stageCategory - 1];
for (var i = 0; i <= req.fields.length - 1; i++) {
if (Xrm.Page.getAttribute(req.fields[i]).getValue()) {
valid = true;
break;
}
}
if (!valid) {
Xrm.Page.data.process.movePrevious(function (result) {
if (result != "success") {
alert('Error forcing back to previous step: ' + result + '. Have fun...');
}
var messageArea = $(window.parent.document).find('.processWarningBar');
messageArea.css('display', 'block');
var textArea = $(window.parent.document).find('.processWarningBar-Text');
textArea.attr('title', 'At least one sales sub-stage has to be selected to move on to next sales stage.');
textArea.text('At least one sales sub-stage has to be selected to move on to next sales stage.');
setTimeout(function () {
var messageArea = $(window.parent.document).find('.processWarningBar');
messageArea.css('display', 'none');
}, 5000);
});
}
}
}
如您所見,一旦階段更改,我將檢查上一階段(當前階段-位置為1)中的步驟是否至少具有一個true
值。
如果沒有,我將移回一個階段( movePrevious
),然后進行一些jQuery欺騙...這有一些缺點(錯誤和警告圖標均顯示在錯誤中,我必須自己隱藏錯誤div,有時在進行驗證時通過后,我進入下一個階段,自定義錯誤消息將閃爍並消失)。
我試圖讓這部分顯示自定義消息:
還有更好的方法嗎? 我在考慮CRM本身在顯示其默認消息時調用的功能。 我試圖找出它們的蹤跡,但它們似乎隱藏得很好。
編輯
我將驗證碼更改為以下答案提出的驗證碼:
if (!valid) {
Xrm.Page.data.process.movePrevious(function (result) {
if (result != "success") {
alert('Error forcing back to previous step: ' + result + '. Have fun...');
}
Xrm.Page.ui.setFormNotification('At least one sales sub-stage has to be selected to move on to next sales stage.', 'ERROR', 'subStageMessage');
setTimeout(function () {
Xrm.Page.ui.clearFormNotification('subStageMessage');
}, 5000);
});
return;
}
else
{
Xrm.Page.ui.clearFormNotification('subStageMessage'); //trying to hide it once the previous stage has passed validation, but error message is still shown...
}
現在的問題是,即使移至下一個階段,也會顯示該消息。 如果驗證失敗,則將用戶返回上一步,然后顯示該消息。 當用戶完成缺少的步驟並轉到下一個階段時,即使未執行顯示該消息的代碼,該消息仍會顯示另外5秒鍾(??)
我正在使用CRM 2016,這是針對商機實體的。
是的,存在更好的方法: Xrm.Page.ui.setFormNotification
// Sample
Xrm.Page.ui.setFormNotification("You have to complete required steps", "INFO", "messageId");
我決定使用Notify.js,並通過使用此Web資源進行相同的操作,解決了重新出現通知的問題。
if (!valid) {
Xrm.Page.data.process.movePrevious(function (result) {
Notify.add('<b>At least one sales sub-stage has to be selected to move on to next sales stage.</b>', 'WARNING', 'subStageMessage', null);
});
}
else {
//if previous stage's steps were all valid, remove all notifications
Notify.remove();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.