For example:

I have a site under this url: http://intranet.contoso.com/news

When I open it i would like to read it's GUID for future use in my custom AssetPortalBrowser.aspx url picker.



Use get_id to get the GUID

var value = SP.Web.get_id();

Example usage:

<script type="text/javascript">  
ExecuteOrDelayUntilScriptLoaded(getSite, "sp.js");  
var context = null;  
var web = null;  
    function getSite() {  
        context = new SP.ClientContext.get_current();  
        web = context.get_web();  
        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));  
    function onSuccessMethod(sender, args) {  
        alert('your are there :' + web.get_title() + '\n ID:' + web.get_id());  
    function onFaiureMethodl(sender, args) {  
        alert('you suck ' + args.get_message() + '\n' + args.get_stackTrace());  
  • My pleasure. Happy SharePointing :) – Falak Mahmood Jan 8 '13 at 21:28

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.