我有一個要求通過JavaScript啓動SP工作流。爲此,我寫了一些代碼行來啓動工作流。但由於未定義的對象,我得到了一個訂閱失敗錯誤。這發生在ExcecuteasyncQuery方法中。所以我沒有得到哪個對象返回未定義的值。我的代碼如下所示。SharePoint工作流訂閱服務失敗
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"> </script>
<script type="text/javascript">
var subID = "3debdbad-db52-4586-87e1-40e4db581da5";
function GetCurrentItemID()
{
var ctx = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
for (item in selectedItems)
{
var itemId = selectedItems[item].id;
startWorkflow(itemId, subID);
}
}
function startWorkflow(itemID, subID) {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription(subID);
context.load(subscription);
context.executeQueryAsync(
function(sender, args){
alert("Subscription load success. Attempting to start workflow.");
var inputParameters = {};
wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem
(subscription, itemID, inputParameters);
context.executeQueryAsync(
function(sender, args){ alert("Successfully starting workflow."); },
function(sender, args){
alert("Failed to start workflow.");
alert("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
},
function(sender,args){
alert("Failed to load subscription.");
alert("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
}
</script>
我在點擊按鈕時調用GetCurrentItemID()函數。但在那個時候,我收到以下錯誤。
無法加載訂閱
無效請求
未定義
可以在任何一個請幫我理清這個問題。提前致謝。
itemId和is返回正確的值並且訂閱返回非空值。 – MAC
生病回覆你。我正在尋找這件事。 –
我們可以做Skype文字嗎? – MAC