1

I want to get list ctx based on GUID.

My requirement is to develop a context menu security webpart.

I want to display the list/library context menu items in my application page which is user selected list/library.

So that they can select the context menu item to hide/disable.

I think in Core.js

function BuildMenuWithInit(ctx)

function BuildMenu(ctx)

above functions is generating the context menu items.

Both functions are taking list/library ctx.

So I want to get the ctx based on list/library GUID.

Can any one provide the solution for this problem, like

function getContextInfo(ListId) {    
    // some logic   
    return ctxT;
}
1

SharePoint JavaScript Library contains the SP.Ribbon.NativeUtility.getCtxForView method that could be used for retrieving Context Info by View id, for example:

//Retrieve Context Info by View Id
var viewId = '{C441B540-C04D-4592-A526-26F57DA6914A}';
var ctxForView = SP.Ribbon.NativeUtility.getCtxForView(viewId);
console.log(currentCtx);

In order to retrieve Context Info by List id the following function could be used:

//Retrieve Context Info by List Id
function findCtxForList(listId)
{ 
   var ctx = null;
   for(var viewId in g_ViewIdToViewCounterMap) {
       var curCtxNo = g_ViewIdToViewCounterMap[viewId];
       var curCtx = g_ctxDict['ctx' + curCtxNo];
       if(curCtx.listName === listId.toUpperCase()) {
           ctx = currentCtx;         
           break;
       }
   }
   return ctx;
}

Usage

var listId = '{C627B132-B9B7-424D-ACA8-C961EB9213C5}';
var ctxForList = findCtxForList(listId);
console.log(ctxForList);
  • your script is not working, i found some jquery script but it works only it the same list or library page. like sp2010/sites/test/Shared%20Documents/Forms/AllItems.aspx but i want to get ctx in custom application page. please refer below link for script nothingbutsharepoint.com/sites/eusp/Pages/… – kavalirakesh Oct 7 '14 at 15:39
  • what exactly "is not working" ? – Vadim Gremyachev Oct 8 '14 at 20:13
  • i tried to run the script but 'var viewId in g_ViewIdToViewCounterMap' and ' var ctxForView = SP.Ribbon.NativeUtility.getCtxForView(viewId);' is returning undefined, its not returning the ctx. note : i need to get the ctx in application page not in the same list or library page. so then only i can display the menu options to the client in my context security webpart. – kavalirakesh Oct 9 '14 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.