var web;
var listid;
var listitem = [];
var siteCollection;
var notifyId = '';
var processingCount = 0;
var link;
function Test()
{
MyItems();
}
function getquerystring(key)
{
var qsarr = new Array();
var qs = location.search.substring(1);
var singleqs = new Array();
var str ="";
qsarr = qs.split('&');
for( i=0; i
singleqs = qsarr[i].split('=');
if(singleqs[0]==key){
return singleqs[1];
}
}
return "";
}
function BulkReceiveAll()
{
var Values= getquerystring('Values');
var WorkFlowURL= getquerystring('WorkFlowURL');
var TaskListID= getquerystring('TaskListID');
BulkApproveFun(Values,TaskListID) ;
}
function BulkApproveFun(taskid,TaskListID)
{ var tListID=TaskListID;
var re = /{/g;
var result = tListID.replace(re, "");
var re2=/}/g;
var TaskList=result.replace(re2, "");
var ctx = SP.ClientContext.get_current();
this.siteCollection = ctx.get_site();
this.web = ctx.get_web();
this.listid = TaskList;
ctx.load(this.siteCollection);
var tt = taskid.split('*');
for (var i = 0; i < tt.length - 1; i++) {
this.listitem.push(sdlist.getItemById(tt[i]));
ctx.load(this.listitem[i]);
}
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function MyItems()
{
//notifyId = SP.UI.Notify.addNotification("Processing...", true);
var ctx = SP.ClientContext.get_current();
this.siteCollection = ctx.get_site();
this.web = ctx.get_web();
this.listid = SP.ListOperation.Selection.getSelectedList();
var sdlist = this.web.get_lists().getById(listid);
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var selectedItems = items;
ctx.load(this.siteCollection);
for (var i = 0; i <= items.length - 1; i++) {
this.listitem.push(sdlist.getItemById(items[i].id));
ctx.load(this.listitem[i]);
}
ctx.executeQueryAsync(Function.createDelegate(this, this.onQueryS), Function.createDelegate(this, this.onQueryFailed));
}
function onQueryS(sender, args) {
link ="";
var workflowlink="";
var WLink="";
var tListID="";
for (var i = 0; i <= this.listitem.length - 1; i++) {
var workflowlink = this.listitem[i].get_item('WorkflowLink');
if(link=="")
link +=this.listitem[i].get_id().toString()+"*";
else
link +=this.listitem[i].get_id().toString()+"*";
var WlinkIndex=workflowlink.get_url().toString().lastIndexOf("=");
WLink+=workflowlink.get_url().toString().substr(WlinkIndex+1)+"*";
//ApproveTasks(this.listid, GetQueryParam("ID", workflowlink.get_url()), this.listitem[i].get_id(), workflowlink.get_url());
}
//WLink=WLink.substr(0,WLink.lastIndexOf("*")-1);
tListID=this.listid;
//window.location.href = "http://10.100.32.13:2014/SitePages/BulkReceiveCases.aspx?Values="+link+"&WorkFlowURL="+WLink+"&TaskListID="+tListID;
var link="http://10.100.32.13:2014/SitePages/BulkReceiveCases.aspx?Values="+link+"&WorkFlowURL="+WLink+"&TaskListID="+tListID;
openlinkInDialog(link);
}
function openlinkInDialog( pUrl )
{
debugger;
SP.UI.ModalDialog.showModalDialog(
{
url: pUrl,
width: 900,
height: 700,
title: "Bulk Receive Cases"
}
);
}
function ApproveItems()
{
var ctx = SP.ClientContext.get_current();
this.siteCollection = ctx.get_site();
this.web = ctx.get_web();
this.listid = SP.ListOperation.Selection.getSelectedList();
var sdlist = this.web.get_lists().getById(listid);
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var selectedItems = items;
ctx.load(this.siteCollection);
for (var i = 0; i <= items.length - 1; i++) {
this.listitem.push(sdlist.getItemById(items[i].id));
ctx.load(this.listitem[i]);
}
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
link ="";
var workflowlink="";
for (var i = 0; i <= this.listitem.length - 1; i++) {
var workflowlink = this.listitem[i].get_item('WorkflowLink');
if(link=="")
link +=this.listitem[i].get_id().toString()+"*";
else
link +=this.listitem[i].get_id().toString()+"*";
ApproveTasks(this.listid, GetQueryParam("ID", workflowlink.get_url()), this.listitem[i].get_id(), workflowlink.get_url());
}
}
function GetQueryParam(key, querystring) {
var params = querystring.split("?");
for (var i = 0; i <= params.length - 1; i++) {
if (params[i].split("=")[0].toLowerCase() == key.toLowerCase())
return params[i].split("=")[1];
}
}
function onQueryFailed(sender, args) {
Y = args;
}
function ApproveTasks(tasklistId, itemId, taskId, item) {
GetCaseID(taskId);
var soapEnv = "
$.ajax({
url: siteCollection.get_url() + "/_vti_bin/workflow.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/workflow/AlterToDo");
},
type: "POST",
dataType: "xml",
data: soapEnv,
success: Function.createDelegate(this, this.processResult),
error:reportError,
contentType: "text/xml; charset=\"utf-8\""
});
}
var processingComplete;
function processResult(xData, status) {
processingCount++;
if (processingCount == this.listitem.length) {
SP.UI.Notify.removeNotification(notifyId);
notifyId = '';
SP.UI.Notify.addNotification("Items Approved", false);
location.reload();
}
}
function reportError(xData, status) {
processingCount++;
SP.UI.Notify.addNotification("Multi Item Approval failed", true);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var targetListItem;
var CasesListItem;
var CaseID;
var ItemID;
function GetCaseID(item) {
var ctx = new SP.ClientContext();
var targetList = ctx.get_web().get_lists().getByTitle('Workflow Tasks');
targetListItem = targetList.getItemById(item);
ctx.load(targetListItem, 'CaseID');
ctx.executeQueryAsync(onQuerySu, onQueryFa);
}
function onQuerySu() {
CaseID=targetListItem.get_item('CaseID');
UpdateCaseInformation(CaseID);
//GetCasesItemID(CaseID);
//BulkUpdate(CaseID);
//getProducts(CaseID);
// GetCasesListID(CaseID);
}
/////////////////////////////////////////////////////////////
function UpdateCaseInformation(CaseID)
{
try
{
myListcontext = new SP.ClientContext.get_current();
var web = myListcontext.get_web();
var myList = web.get_lists().getByTitle('Cases');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("
this.myListItemCollection = myList.getItems(camlQuery);
myListcontext.load(myListItemCollection);
/*Because you’re not on the server side you’ll call the executeQueryAsync method that takes two delegates as parameters the first one will be executed when your request is successful and the second if failed.*/
myListcontext.executeQueryAsync(updateItems);
}
catch(exc)
{
}
}
function updateItems(sender, args)
{
try
{
debugger;
var listItemEnumerator = myListItemCollection.getEnumerator();
$("[id$='_V1_I1_T7']")
var btbOff = $("[id$='customcontrol1_upLevelDiv'] #content").text();
var btbIns=$("[id$='customcontrol0_upLevelDiv'] #content").text();
var Prio=$("[id$='_V1_I1_D4'] option:selected").val();
var status=0;
var user=$("[id$='_V1_I1_T6']").val();
var getbtbOff = $("[id$='customcontrol1_upLevelDiv'] #content").text().toLowerCase().replace(' ','');
var getuser= $("[id$='_V1_I1_T6']").val().toLowerCase().split("\\")[1].toString().replace('.','');
if(getbtbOff==getuser){
status =3;
}else{
status=1;
}
while (listItemEnumerator.moveNext())
{
var myListItem = listItemEnumerator.get_current();
myListItem.set_item('Priority', Prio);
myListItem.set_item('Status', status);
myListItem.set_item('BTBInspector', btbIns);
myListItem.set_item('PIN', 123);
myListItem.update();
}
myListcontext.executeQueryAsync(ItemsUpdated, failureMethod);
}
catch(exc)
{
}
}
No comments:
Post a Comment