Active Directory Service Instance values for Multiple Domains for K2

If your organization has multiple domains, normally the AD service instance might register only 1 of it especially the ones for K2 service account or the one who installed / upgrade it.

After installation or upgrade, you can update the AD instance with the following sample for support of multiple domains.

LDAP:

LDAP://DC=CompanyA,DC=COM;LDAP://DC=CompanyB,DC=COM;LDAP://DC=CompanyC,DC=COM

NetBios

CompanyA;CompanyB;CompanyC

Separate each of the LDAP and Netbios with semi colon (;) End it up with no symbol

Posted in K2 | Leave a comment

Overcome List Threshold Limit on SharePoint

When you are using code to query a list especially those with a lot of columns or has more than 5k items, you will hit the error which contains the message of “list threshold limit”.

Here’s your regular code to get list item collection with CAML query.

List listAM = clientContext.Web.Lists.GetByTitle("Matrix");

StringBuilder sbQuery = new StringBuilder();
sbQuery.Append("<View>");
sbQuery.Append("<ViewFields>");
sbQuery.Append("<FieldRef Name='ID' />");
//you can add your own lines for more fields
sbQuery.Append("</ViewFields>");
sbQuery.Append("</View>");

CamlQuery caml = new CamlQuery();
caml.ViewXml = sbQuery.ToString();

ListItemCollection amItems = listAM.GetItems(caml);
clientContext.Load(amItems);
clientContext.ExecuteQuery();

foreach (ListItem am in amItems)
{
    //whatever you need to do with the item collection
}

The code above works perfectly fine until your list has more than 5k of items and you will hit the error of list threshold limit. How do you overcome it? SharePoint has a way to overcome it by utilising the ListItemCollectionPosition class that will retrieve the items in batch according to the conditions in the CAML query and number set for each retrieval.

Here’s the sample of updated code by adding the class of ListItemCollectionPosition and batch number. Once you can differentiate the additional code with regular code above, you can update your code with ease.

List listAM = clientContext.Web.Lists.GetByTitle("Matrix");

StringBuilder sbQuery = new StringBuilder();
sbQuery.Append("<View>");
sbQuery.Append("<ViewFields>");
sbQuery.Append("<FieldRef Name='ID' />");
//you can add your own lines for more fields
sbQuery.Append("</ViewFields>");
//sample to retrieve by 2000 each batch
sbQuery.Append("<RowLimit>2000</RowLimit>");
sbQuery.Append("</View>");

CamlQuery caml = new CamlQuery();
caml.ViewXml = sbQuery.ToString();
ListItemCollectionPosition licp = null;

while (true)
{
    caml.ListItemCollectionPosition = licp;

    ListItemCollection amItems = listAM.GetItems(caml);
    clientContext.Load(amItems);
    clientContext.ExecuteQuery();
    licp = amItems.ListItemCollectionPosition;

    foreach (ListItem am in amItems)
    {
       //whatever you need to do with the item collection
    }

    //this to keep looping until no more item to fetch
    if (licp == null)
    { break; }
}

Posted in Programming, SharePoint | Leave a comment

Accessing the Correct Control in a Page with Same Multiple Webparts Through Javascript

You have just make some control and Javascript in your webpart which looks similar as below:

Control
<div id=”btnX”></div>

Javascript

$('#btnX').click(function () {
$('#myTargetControl')...
..
});

Then you deployed it to your environment and place the webpart in a page. After adding the first webpart, you find that your script works as it intended. You might have some requirements to place the same webpart more than once in the same page. You proceed to add the same part a few more times in the same page.

When you tested it, you realised that the same script actually triggered multiple times (perhaps 5 times if you got 5 same webparts in a page)

How to solve it to make sure only the correct control is selected when you try trigger the script from a certain webpart or in this case the button that is in the same webpart as the targetted control?

Here’s the tricks for both control and javascript

Control – add the runat tag
<div id=”btnX” runat=”server”></div>

Javascript
– instead of calling the button ID directly, use ClientID as it will be unique for every webpart
– as long as the control and button are within same webpart and div, they will have same prefix which added with their own id. This case btnX and myTargetControl.
– the alert is put for testing purpose.

$('#<%=btnX.ClientID%>').click(function () {
var _thisX = $(this);
var _thisMyControl = _thisX.attr('id').replace('btnX', 'myTargetControl')
//alert(_thisX.attr('id') + "~~~" + _thisMyControl);
$('#'+_thisMyControl)...
..
});


Posted in Programming, SharePoint, Workarounds and Tricks | Leave a comment