Wednesday, May 24, 2017

IManage create workspace with folder structure

/////////////////////////////////////////////////////////////////////////////////////////
$.ajaxSetup({async: false});
var cache = {};
cache[ "group_id" ] ="";//"blah"
cache["baseurl"] = 'https://blah/api/v1/';
cache["user_id"] = "ws_creator";
cache["pwd"] = "test";
cache["FolderIds"] =[];

function getToken( ){
console.log("getToken");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'session/login',
type: 'put',
data: JSON.stringify({
user_id:cache["user_id"],
password:cache["pwd"]
}),
headers: {
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
                cache[ "Token"  ] = resp["X-Auth-Token"];
console.log("getToken:success");
            },
failure: function( resp ){
console.log("getToken:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////
function CreateWorkspace(ClientID , EntityID, wsName, groupId,accessType){
console.log("CreateWorkspace");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] + 'workspaces',
type: 'post',
data: JSON.stringify({
database: "Blah",
custom1:ClientID ,
custom2:EntityID ,
default_security: "private", //change back to private
name: wsName
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
cache[ "group_id"  ] = groupId;
addGroup(resp.data.id, "workspaces", accessType);
                cache[ "workspace_id"  ] = resp.data.id;
console.log("CreateWorkspace:success");
            },
failure: function( resp ){
console.log("CreateWorkspace:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToWorkspace(fname,accessType,documentGroup ){
console.log("AddFolderToWorkspace");
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "workspace_id"  ]  + '/folders',
type: 'post',
data: JSON.stringify({
 database:"Blah",
 name:fname,
 default_security:"inherit",
 profile:
  {
 author:cache["user_id"],
 class:"DOC",
     comment:"",
 custom29:documentGroup
        }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
//cache[ "group_id"  ] = ""; //remove
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root":"","name":fname,id :resp.data.id});
console.log("AddFolderToWorkspace:success");
            },
failure: function( resp ){
console.log("AddFolderToWorkspace:failure");
console.log(fname);
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"

what are the possible values for user types?
"user" or "group"
*/
function addGroup(objectID, type, accessType){
//type documents, workspaces, folders
//debugger;
console.log("cache[ 'group_id'] " + cache[ "group_id" ]  );
if(cache[ "group_id" ] !==""){
 return $.when(
   $.ajax({
url: cache["baseurl"] + type +  '/'  + objectID + "/security",
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({
include:
[{access_level: accessType,
id: cache[ "group_id" ],
type: "group"
}]
}),
            success: function( resp ){
//debugger;
//user_type
               //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("addGroup:success");
            },
failure: function( resp ){
//debugger;
console.log("addGroup:failure");
console.log(resp);
            }
        })
    );
}
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToFolder(root, father, fname ,accessType,taxYear){
console.log("AddFolderToFolder");
console.log(father + "-" + fname);
//debugger;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache["FolderIds"].filter(function (el) {
return el.name == father && el.root == root;
})[0].id + '/folders',
type: 'post',
data: JSON.stringify({
 database:"Blah",
 name:fname,
 default_security:"inherit",
 profile:
  {
 author:cache["user_id"],
 class:"DOC",
     comment:"",
 custom4:taxYear,
 custom29:father
        }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root" : father, name:fname,id :resp.data.id});
console.log("AddFolderToFolder:success");
            },
failure: function( resp ){
console.log("AddFolderToFolder:failure");
console.log(fname);
console.log(resp);
            }
        })
    );
}

/////////////////////////////////////////////////////////////////////////////////////////
getToken()//ClientID , EntityID, wsName, groupId,accessType
    .then(CreateWorkspace("11274","438917","test 2","Blah","read"), function(err) {console.log( err );})
.then(AddFolderToWorkspace("Billing","read","Billing"), function(err) {console.log( err );})
//root, father, fname ,accessType,taxYear
.then(AddFolderToFolder("","Billing","31-Dec-2017","full_access","2017"), function(err) {console.log( err );})
.then(AddFolderToFolder("","Billing","31-Dec-2016","full_access","2016"), function(err) {console.log( err );})

Create Search Folder In Imanage

//########################################################
function GetSearchFolder(SFId ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
//  return d.name  == WSName;
   //});
                //cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function GetWorkspace(WSName ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/search',//  ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
 return d.name  == WSName;
});
                cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id"  ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
  {
 "custom4":TaxYear,
 "container": stripped,
 "databases":"Blah"
  }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
                //cache[ "folder_id"  ] = resp.data.id;
console.log("CreateSearchFolder:success");
            },
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
            }
        })
    );
}
//########################################################
// implementation
//########################################################

getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017"))

loading jquery in dev tools

sorry I lost where I got this from for the HT


var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();

Tuesday, May 23, 2017

wcf JSON deserialization

this
new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(results)
will not work with complex objects

you need to create objects

for example, this is the IManage Login JSON

[DataContract]
    public class IManageUser
    {
        [DataMember(Name = "email")]
        public string email { get; set; }
        [DataMember(Name = "full_name")]
        public string full_name { get; set; }
        [DataMember(Name = "user_id")]
        public string user_id { get; set; }
    }

    [DataContract]
    public class IManageLoginInfo
    {
        [DataMember(Name = "X-Auth-Token")]
        public string X_Auth_Token { get; set; }
        [DataMember(Name = "max_age")]
        public int max_age { get; set; }
        [DataMember(Name = "persona")]
        public string persona { get; set; }
        [DataMember(Name = "user")]
        public IManageUser user { get; set; }

    }

then you could do something like this:
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(resp.GetResponseStream());
                results = sr.ReadToEnd();
                sr.Close();
                IManageLoginInfo info = null;
                using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(results)))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IManageLoginInfo));
                    info = (IManageLoginInfo)serializer.ReadObject(ms);
                }
                this.token = info.X_Auth_Token;

Friday, May 19, 2017

Create search folder in IManage API

//########################################################
function GetSearchFolder(SFId ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
//  return d.name  == WSName;
   //});
                //cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function GetWorkspace(WSName ){
  // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/search',//  ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
 return d.name  == WSName;
});
                cache[ "ws_id"  ] = temp[0].id ;
console.log("GetWorkspace:success");
            },
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
            }
        })
    );
}

//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id"  ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
  {
 "custom4":TaxYear,
 "container": stripped,
 "databases":"Blah"
  }
}),
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
                //cache[ "folder_id"  ] = resp.data.id;
console.log("CreateSearchFolder:success");
            },
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
            }
        })
    );
}
//########################################################
// implementation
//########################################################

getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017b"))




"databases" property is wierd

IManage code to add workspace to my matters

/////////////////////////////////////////////////////////////////////////////////////////////
function getWS(wsName ){
    // return either the cached value or jqXHR object wrapped Promise
    return $.when(
        $.ajax({
url: cache["baseurl"] +'workspaces/search',  //goto get the indexer to work - ?name=' +wsName,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
var temp =  resp.data.filter(function(item) {
return item.name == wsName;
});
cache[ "ws_name"  ] =wsName;
                cache[ "ws_id"  ] = temp[0].id;
console.log("getWS:success");
            },
failure: function( resp ){
console.log("getWS:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"

what are the possible values for user types?
"user" or "group"
*/
function addWSToMyMatters(){
 return $.when(
        $.ajax({
url: cache["baseurl"] + 'folders/my-matters/subfolders',
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({ "name":cache[ "ws_name"  ],
"target":
{ "database":"Blah",
"id":cache[ "ws_id"  ],
"subtype":"work",
"wstype":"workspace"}
}),
            success: function( resp ){
debugger;
//user_type
               //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("addWSToMyMatters:success");
            },
failure: function( resp ){
console.log("addWSToMyMatters:failure");
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
getToken().then(getWS("11Blah)"))
.then(addWSToMyMatters());

IManage search by metadata in API

since IManage has this horrible bug that search by metadata doesn't work here is a horrible kluge

///////////////////////////////////////////////////////////////
function getProfile(docid){
 return $.when(
        $.ajax({
url: cache["baseurl"] +'documents/'  + docid ,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
            success: function( resp ){
//debugger;
currentProfile = resp;
console.log("getProfile:success "  + docid);
            },
failure: function( resp ){
console.log("getProfile:failure "  + docid);
console.log(resp);
            }
        })
    );
}
/////////////////////////////////////////////////////////////////////////////////////////////
function SearchDoc(params ){
    // return either the cached value or jqXHR object wrapped Promise
var temp;
    return $.when(
        $.ajax({
url: cache["baseurl"] +'documents/search',
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
temp = resp.data.filter(function(item) {
getProfile(item.id)
//debugger;
if(currentProfile !== null){
for(var key in params) {
//debugger;
if(currentProfile.data[key] === undefined || currentProfile.data[key] != params[key])
return false;
}
return true;
}
else{
return false;
}

});
debugger;
//return temp;
              //  cache[ "doc_id"  ] = resp.data[0].id;
console.log("getDoc:success");
            },
failure: function( resp ){
console.log("getDoc:failure");
console.log(resp);
            }
        })
    );
}
///////////////////////////////////////////////////////////////
p ={custom4:"2015"};
getToken().then(SearchDoc(p))

Monday, May 15, 2017

Adding Imanage metadata - JS Example

function AddMetadata(customField, customValue , customDescription, parentValue){
    // return either the cached value or jqXHR object wrapped Promise
var payload ={};
if(parentValue===null){
payload = { database: "Blah",
id: customValue,
description: customDescription,
wstype: customField,
enabled: true,
hipaa: false
};
}
else{
payload = { database: "Blah",
id: customValue,
description: customDescription,
wstype: customField,
enabled: true,
hipaa: false,
parent: {
id: parentValue
},
};
}


    return $.when(
       // cache[ "Token" ] ||
        $.ajax({
url: cache["baseurl"] +'customs/'+ customField,
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token"  ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify(payload),
            success: function( resp ){
//debugger;
//cache[ "doc_id"  ] = resp.data[0].id  ;
console.log("AddMetadata:success");
            },
failure: function( resp ){
console.log("AddMetadata:failure");
console.log(resp);
            }
        })
    );
}
///////////////////////////////////////////////////////////////

IManage groups

NOS values
  • 6 - Active Directory
  • 2 - Virtual
An external user or a user in an external group will only have access to workspaces that have explicit access. So public workspaces will not be visible for external users.

Friday, May 12, 2017

IManage work installation issues

we have a firewall that only allows calls to 443 and 80 ports
so you cant communicate to the IManage server unless ports 1080, 1081 are opened

Imanage uploading a file the second time

There is something that is very annoying with iManage concerning uploading documents









If you upload a document to a folder twice you will get 2 different documents , not a choice for overwriting or a new version


This is true if you drag and drop or use file upload

To get a new version you need to either


















Or edit the doc and save as new version in imanage word plugin



This, BTW, is the default behavior in desk site, but you can change that in the registry


  • HKEY_CURRENT_USER\Software\Interwoven\WorkSite\8.0\Common\Advanced
    Options
    Set the following DWORD value:
    Name: Default SaveAs Option
    Values:
    1 – The New Document option is selected by default.
    2 – The Replace Original option is selected by default.
    3 – The New Version option is selected by default.
In desk site there is a different problem in that when you upload a doc you have to fill the author (it’s not set  from the user who’s logged in) and it doesn’t figure out the class


In this instance the web is better