Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing The Vault API from JavaScript

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
1228 Views, 5 Replies

Accessing The Vault API from JavaScript

I noticed on http://justonesandzeros.typepad.com that they have a widget to update change order lists using javascript.  I would like to do the same thing using the 2009 API version.

 

 

<script type="text/javascript">
function sendRequest(url, action, soap)
{
	var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
	xmlHttp.open("POST", url, false);
	xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	xmlHttp.setRequestHeader("SOAPAction", action);
	xmlHttp.send(soap);
	document.write(xmlHttp.responseXML);
	return xmlHttp.responseXML;
}

function signIn(username, password, server, vault)
{
	var soap = 	"<?xml version='1.0' encoding='utf-8'?>" +
			"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
  			"<soap:Body>" +
    			"<SignIn xmlns='http://" + server + "/AutodeskDM/Services/Security/01/17/2008/'>" +
      			"<userName>" + username + "</userName>" +
      			"<userPassword>" + password + "</userPassword>" +
      			"<knowledgeVault>" + vault + "</knowledgeVault>" +
    			"</SignIn>" +
  			"</soap:Body>" +
		   	"</soap:Envelope>";
				
	var loginContext = null;
	try
	{
		var responseXML = sendRequest("http://" + server + "/AutodeskDM/Services/SecurityService.asmx", "http://" + server + "/AutodeskDM/Services/Security/01/17/2008/SignIn", soap);
		var ticket = responseXML.selectSingleNode("//Ticket").text;
		var userId = responseXML.selectSingleNode("//UserId").text;
		var loginContext = userID + " " + ticket;

		document.write(loginContext);
	}
	catch(e)
	{
		throw new Error(100, "Log in failed.");

	}
	return loginContext;
}

signIn('mspears', 'password', 'config-mgmt-srv', 'Unique Vault');
</script>

Does the source code look correct? Because I keep on getting Error 100, and I am supplying the correct credintals.

 

5 REPLIES 5
Message 2 of 6
Redmond.D
in reply to: Anonymous

First, the error 100 you mention is your own programs error code, not Vault's,  Posting the contents of the exception would be helpful.

 

Second, your code is missing several things when compared to the Vault Gadget example.  For example, your code doesn't have a <wsu:Timestamp> tag.  The timestamp is pretty important.  Vault server will reject a call if the client and server clocks are too far out of sync.

So make sure your code provides all the needed XML data.



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 3 of 6
Anonymous
in reply to: Redmond.D

Here is the code I'm using to try and access a 2009 Data Management Server:

changes I made were from 1/11/2011 or whatever the new date was to 01/17/2008 and I changed

GetChangeOrderWorklistLiteForCurrentUser to GetChangeOrderWorklistForCurrentUser

Here's Main.html:

 

 

<html xmlns="http://www.w3.org/1999/xhtml">
<!--   
  This file is part of the Autodesk Vault API Code Samples.

  Copyright (C) Autodesk Inc.  All rights reserved.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
-->
<!-- Version 1.0.1.0 -->
	<head>
		<script language="javascript">
			function LoginContext(userId, ticket, server, vault)
			{
				this.userId = userId;
				this.ticket = ticket;
				this.server = server;
				this.vault = vault;
			}
			
			function ChangeOrder(id, number, title, description, properties)
			{
				this.id = id;
				this.number = number;
				this.title = title;
				this.description = description;
				this.properties = properties;
			}
			
			function PropertyDef(id, type, displayName, sysName)
			{
				this.id = id;
				this.type = type;
				this.displayName = displayName;
				this.sysName = sysName;
			}
			
			function Property(propertyDef, value)
			{
				this.propertyDef = propertyDef;
				this.value = value;
			}

			//--[Vault Proxy Functions]------------------------------------------------------------
			function signIn(username, password, server, vault)
			{
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" + 
					"<soap:Header>" + 
					"<wsa:Action>http://AutodeskDM/Services/Security/01/17/2008/SignIn</wsa:Action>" + 
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" + 
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" + 
					"</wsa:ReplyTo>" + 
					"<wsa:To>http://" + server + "/AutodeskDM/Services/SecurityService.asmx</wsa:To>" + 
					"<wsse:Security>" + 
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" + 
					"</wsu:Timestamp>" + 
					"</wsse:Security>" + 
					"</soap:Header>" + 
					"<soap:Body>" + 
					"<SignIn xmlns='http://AutodeskDM/Services/Security/01/17/2008/'>" + 
					"<userName>" + username + "</userName>" + 
					"<userPassword>" + password + "</userPassword>" +
					"<knowledgeVault>" + vault + "</knowledgeVault>" + 
					"</SignIn>" + 
					"</soap:Body>" + 
					"</soap:Envelope>";
				
				var loginContext = null;
				try
				{
					var responseXML = sendRequest("http://" + server + "/AutodeskDM/Services/SecurityService.asmx", "http://AutodeskDM/Services/Security/01/17/2008/SignIn", soap);
					var ticket = responseXML.selectSingleNode("//Ticket").text;
					var userId = responseXML.selectSingleNode("//UserId").text
					loginContext = new LoginContext(userId, ticket, server, vault);
				}
				catch(e)
				{
					throw new Error(100, "Log in failed.");
				}
				return loginContext;
			}
			function signInWinAuth(server, vault)
			{
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" + 
					"<soap:Header>" + 
					"<wsa:Action>http://AutodeskDM/Services/WinAuthService/01/17/2008/SignIn</wsa:Action>" + 
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" + 
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" + 
					"</wsa:ReplyTo>" + 
					"<wsa:To>http://" + server + "/AutodeskDM/Services/WinAuth/WinAuthService.asmx</wsa:To>" + 
					"<wsse:Security>" + 
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" + 
					"</wsu:Timestamp>" + 
					"</wsse:Security>" + 
					"</soap:Header>" + 
					"<soap:Body>" + 
					"<SignIn xmlns='http://AutodeskDM/Services/WinAuthService/01/17/2008/'>" + 
					"<knowledgeVault>" + vault + "</knowledgeVault>" + 
					"</SignIn>" + 
					"</soap:Body>" + 
					"</soap:Envelope>";
          
				var loginContext = null;
				try
				{
					var responseXML = sendRequest("http://" + server + "/AutodeskDM/Services/WinAuth/WinAuthService.asmx", "http://AutodeskDM/Services/WinAuthService/01/17/2008/SignIn", soap);
					var ticket = responseXML.selectSingleNode("//Ticket").text;
					var userId = responseXML.selectSingleNode("//UserId").text
					loginContext = new LoginContext(userId, ticket, server, vault);
				}
				catch(e)
				{
					throw new Error(100, "Log in failed.");
				}
				return loginContext;
			}
			function signOut(loginContext)
			{
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" + 
					"<soap:Header>" +
					"<SecurityHeader xmlns='http://AutodeskDM/Services/Security/01/17/2008/'>" +
					"<Ticket>" + loginContext.ticket + "</Ticket>" + 
					"<UserId>" + loginContext.userId + "</UserId>" +
					"</SecurityHeader>" + 
					"<wsa:Action>http://AutodeskDM/Services/Security/01/17/2008/SignOut</wsa:Action>" +
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" +
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
					"</wsa:ReplyTo>" +
					"<wsa:To>http://" + loginContext.server + "/AutodeskDM/Services/SecurityService.asmx</wsa:To>" +
					"<wsse:Security>" + 
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" +
					"</wsu:Timestamp>" +
					"</wsse:Security>" +
					"</soap:Header>" +
					"<soap:Body>" +
					"<SignOut xmlns='http://AutodeskDM/Services/Security/01/17/2008/' />" +
					"</soap:Body>" +
					"</soap:Envelope>";
				
				try
				{
					var responseXML = sendRequest("http://" + loginContext.server + "/AutodeskDM/Services/SecurityService.asmx", "http://AutodeskDM/Services/Security/01/17/2008/SignOut", soap);
				}
				catch(e)
				{
					throw new Error(110, "Log out failed.");
				}
			}
			
			function getChangeOrders(loginContext)
			{
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" +
					"<soap:Header>" +
					"<SecurityHeader xmlns='http://AutodeskDM/Services/ChangeOrderService/01/17/2008/'>" +
					"<Ticket>" + loginContext.ticket + "</Ticket>" + 
					"<UserId>" + loginContext.userId + "</UserId>" +
					"</SecurityHeader>" +
					"<wsa:Action>http://AutodeskDM/Services/ChangeOrderService/01/17/2008/GetChangeOrderWorklistForCurrentUser</wsa:Action>" +
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" +
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
					"</wsa:ReplyTo>" +
					"<wsa:To>http://" + loginContext.server + "/AutodeskDM/Services/ChangeOrderService.asmx</wsa:To>" +
					"<wsse:Security>" +
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" +
					"</wsu:Timestamp>" +
					"</wsse:Security>" +
					"</soap:Header>" +
					"<soap:Body>" +
					"<GetChangeOrderWorklistForCurrentUser xmlns='http://AutodeskDM/Services/ChangeOrderService/01/17/2008/' />" +
					"</soap:Body>" +
					"</soap:Envelope>";
				
				var changeOrders = null;
				try
				{
					var responseXML = sendRequest("http://" + loginContext.server + "/AutodeskDM/Services/ChangeOrderService.asmx", "http://AutodeskDM/Services/ChangeOrderService/01/17/2008/GetChangeOrderWorklistForCurrentUser", soap);
					var xmlNodes = responseXML.selectNodes("//ChangeOrder");
					var propertyDefs = getChangeOrderPropertyDefs(loginContext);
					
					if(xmlNodes != null && xmlNodes.length > 0)
					{
						changeOrders = new Array();
						for(var i = 0; i < xmlNodes.length; i++)
						{
							var id = xmlNodes.item(i).getAttribute("Id");
							var number = xmlNodes.item(i).getAttribute("Num");
							var title = xmlNodes.item(i).getAttribute("Title")
							var description = xmlNodes.item(i).getAttribute("Descr")
							var properties = getChangeOrderProperties(id, propertyDefs, loginContext)
							changeOrders[i] = new ChangeOrder(id, number, title, description, properties);
						}
					}
				}
				catch(e){}
				return changeOrders;
			}
			
			function getChangeOrderPropertyDefs(loginContext)
			{
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" +
					"<soap:Header>" +
					"<SecurityHeader xmlns='http://AutodeskDM/Services/Property/01/17/2008/'>" +
					"<Ticket>" + loginContext.ticket + "</Ticket>" + 
					"<UserId>" + loginContext.userId + "</UserId>" +
					"</SecurityHeader>" +
					"<wsa:Action>http://AutodeskDM/Services/Property/01/17/2008/GetPropertyDefinitionsByEntityClassId</wsa:Action>" +
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" +
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
					"</wsa:ReplyTo>" +
					"<wsa:To>http://" + loginContext.server + "/AutodeskDM/Services/PropertyService.asmx</wsa:To>" +
					"<wsse:Security>" +
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" +
					"</wsu:Timestamp>" +
					"</wsse:Security>" +
					"</soap:Header>" +
					"<soap:Body>" +
					"<GetPropertyDefinitionsByEntityClassId xmlns='http://AutodeskDM/Services/Property/01/17/2008/'>" +
					"<entityClassId>CO</entityClassId>" +
					"</GetPropertyDefinitionsByEntityClassId>" +
					"</soap:Body>" +
					"</soap:Envelope>";
					
				var propertyDefs = null;
				
				try
				{
					var responseXML = sendRequest("http://" + loginContext.server + "/AutodeskDM/Services/PropertyService.asmx", "http://AutodeskDM/Services/Property/01/17/2008/GetPropertyDefinitionsByEntityClassId", soap);
					var xmlNodes = responseXML.selectNodes("//PropDef");
					
					
					if(xmlNodes != null && xmlNodes.length > 0)
					{
						propertyDefs = new Array();
						for(var i = 0; i < xmlNodes.length; i++)
						{
							var id = xmlNodes.item(i).getAttribute("Id");
							var type = xmlNodes.item(i).getAttribute("Typ");
							var displayName = xmlNodes.item(i).getAttribute("DispName");
							var sysName = xmlNodes.item(i).getAttribute("SysName");
							propertyDefs[i] = new PropertyDef(id, type, displayName, sysName);
						}
					}
				}
				catch(e){}
				
				return propertyDefs;
			}
			
			function getChangeOrderProperties(id, propertyDefs, loginContext)
			{
				var ids = "";
				for(var i = 0; i < propertyDefs.length; i++)
					ids += "<long>" + propertyDefs[i].id + "</long>";
				
				var soap = "<?xml version='1.0' encoding='utf-8'?>" + 
					"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" +
					"<soap:Header>" +
					"<SecurityHeader xmlns='http://AutodeskDM/Services/Property/01/17/2008/'>" +
					"<Ticket>" + loginContext.ticket + "</Ticket>" + 
					"<UserId>" + loginContext.userId + "</UserId>" +
					"</SecurityHeader>" +
					"<wsa:Action>http://AutodeskDM/Services/Property/01/17/2008/GetProperties</wsa:Action>" +
					"<wsa:MessageID>urn:uuid:" + getGuid() + "</wsa:MessageID>" + 
					"<wsa:ReplyTo>" +
					"<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
					"</wsa:ReplyTo>" +
					"<wsa:To>http://" + loginContext.server + "/AutodeskDM/Services/PropertyService.asmx</wsa:To>" +
					"<wsse:Security>" +
					"<wsu:Timestamp wsu:Id='Timestamp-" + getGuid() + "'>" + 
					"<wsu:Created>" + getWsuDate() + "</wsu:Created>" +
					"<wsu:Expires>" + getWsuDate(5) + "</wsu:Expires>" +
					"</wsu:Timestamp>" +
					"</wsse:Security>" +
					"</soap:Header>" +
					"<soap:Body>" +
					"<GetProperties xmlns='http://AutodeskDM/Services/Property/01/17/2008/'>" +
					"<entityClassId>CO</entityClassId>" +
					"<entityIds><long>" + id + "</long></entityIds>" +
					"<propertyDefIds>" + ids + "</propertyDefIds>" +
					"</GetProperties>" +
					"</soap:Body>" +
					"</soap:Envelope>";

				var properties = null;
				try
				{
					var responseXML = sendRequest("http://" + loginContext.server + "/AutodeskDM/Services/PropertyService.asmx", "http://AutodeskDM/Services/Property/01/17/2008/GetProperties", soap);
					var xmlNodes = responseXML.selectNodes("//PropInst");
					
					if(xmlNodes != null && xmlNodes.length > 0)
					{
						properties = new Array();
						for(var i = 0; i < xmlNodes.length; i++)
						{
							var propertyDefId = xmlNodes.item(i).getAttribute("PropDefId");
							var propertyValue = xmlNodes.item(i).text;					
							var propertyDef = null;
							for(var j = 0; j < propertyDefs.length; j++)
								if(propertyDefs[j].id == propertyDefId)
									propertyDef = propertyDefs[j];
							if(propertyValue == null || propertyValue.length == 0)
								propertyValue = "(None)";
							else if(propertyDef.type == "DateTime")
							{
								var dt = getJSDateFromDNDate(propertyValue);
								propertyValue = dt.toLocaleDateString();
							}
							properties[i] = new Property(propertyDef, propertyValue);
						}
					}
				}
				catch(e){}
				return properties;
			}
			
			//--[Vault Utility Functions]----------------------------------------------------------
			function getWsuDate(increment)
			{
				var date = new Date();
				if(increment != null) date.setMinutes(date.getMinutes() + increment);
				var y = date.getUTCFullYear();
				var m = date.getUTCMonth() + 1;	//Add one since this returns values 0-11
				m = (m < 10 ? "0" + "" + m : m);
				var d = date.getUTCDate();
				d = (d < 10 ? "0" + "" + d : d);
				var h = date.getUTCHours();
				h = (h < 10 ? "0" + "" + h : h);
				var mn = date.getUTCMinutes();
				mn = (mn < 10 ? "0" + "" + mn : mn);
				var s = date.getSeconds();
				s = (s < 10 ? "0" + "" + s : s);

				return y + "-" + m + "-" + d + "T" + h + ":" + mn + ":" + s + "Z";
			}
			function getJSDateFromDNDate(dt)
			{
				//2010-10-09T09:16:01.853-04:00
				var d = dt.slice(0, dt.indexOf("T"));
				var ds = d.split("-");
				var t = dt.slice(dt.indexOf("T") + 1, dt.indexOf("."));
				var ts = t.split(":");
				var o = dt.slice(dt.lastIndexOf("-") + 1);
				var os = o.split(":");
				var tmp = (new Date().getTimezoneOffset() / 60) - parseInt(os[0]);
				return new Date(ds[0], ds[1], ds[2], ts[0] - tmp, ts[1], ts[2]);
			}
			function sendRequest(url, action, soap)
			{
				var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
				xmlHttp.open("POST", url, false);
				xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
				xmlHttp.setRequestHeader("SOAPAction", action);
				xmlHttp.send(soap);
				return xmlHttp.responseXML;
			}
			function getGuid()
			{
				return('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {     var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);     return v.toString(16); }).toUpperCase());
			}
		</script>
		
		
		
		
		
		
		
		
		
		
		<script language="javascript">
			// View globals
			var g_selectedCoDiv = null;
			
			// Data model globals
			var g_settings = null;
			var g_coDivToCoMap = null;
			
			// Constants
			var CO_CLASS_NAME = "co";
			var CO_HOVER_CLASS_NAME = "coHover";
			var CO_SELECTED_CLASS_NAME = "coSelected";
			var CO_TITLE_CLASS_NAME = "coTitle";
			var CO_DESCRIPTION_CLASS_NAME = "coDescription";
			var CO_SPACER_CLASS_NAME = "coSpacer";
			var CO_PROP_NAME_CLASS_NAME = "propertyName";
			var CO_PROP_VALUE_CLASS_NAME = "propertyValue";
			var GADGET_FLYOUT_FILE = "flyout.html";
			var GADGET_SETTINGS_FILE = "settings.html";
			
			function setupGadget()
			{
				System.Gadget.Flyout.file = GADGET_FLYOUT_FILE;
				System.Gadget.settingsUI = GADGET_SETTINGS_FILE;
				
				System.Gadget.onSettingsClosed = function(e)
				{
					if(e.closeAction == e.Action.commit)
					{
						g_settings = getSettings();
						stopCounter();
						refreshCoList();
						startCounter(g_settings["refreshRate"]);
					}
				}
				
				g_settings = getSettings();
				refreshCoList();
				startCounter(g_settings["refreshRate"]);
			}
			
			function getSettings()
			{
				var settings = new Array();
				settings["username"] = System.Gadget.Settings.read("username");
				settings["password"] = System.Gadget.Settings.read("password");
				settings["server"] = System.Gadget.Settings.read("server");
				settings["vault"] = System.Gadget.Settings.read("vault");
				settings["windowsAuth"] = System.Gadget.Settings.read("windowsAuth");
				settings["refreshRate"] = System.Gadget.Settings.read("refreshRate");
				return settings;
			}
			
			function getCos()
			{
				var context = null;
				if(g_settings["windowsAuth"])
					context = signInWinAuth(g_settings["server"], g_settings["vault"]);
				else
					//context = signIn("Administrator", "", "localhost", "vault");
					context = signIn(g_settings["username"], g_settings["password"], g_settings["server"], g_settings["vault"]);
					
				var changeOrders = getChangeOrders(context);
				if(changeOrders != null && changeOrders.length > 0)
				{
					changeOrders.sort(function(a,b){return a.number.localeCompare(b.number)});
					for(i = 0; i < changeOrders.length; i++)
						changeOrders[i].properties.sort(function(a,b){return a.propertyDef.displayName.localeCompare(b.propertyDef.displayName)});
					signOut(context);
				}
				return changeOrders;
			}
			function refreshCoList()
			{
				try
				{
					setCounterEnabled(false);
					var changeOrders = getCos();
					writeCoList(changeOrders);
					writeLoginInformation(g_settings["username"], g_settings["server"], g_settings["vault"]);
					setCounterEnabled(true);
				}
				catch(e)
				{
					setCounterEnabled(false);
					resetCounter();
					loginContainer.innerText = "";
					coContainer.innerHTML = "<table width=\"100%\" height=\"100%\"><tr><td align=\"center\" valign=\"center\"><font size=\"2\" face=\"Trebuchet MS\" color=\"yellow\">Could not retrieve COs. Please check your gadget settings.</font></td></tr></table>";
				}
			}
			function writeCoList(changeOrders)
			{
				g_coDivToCoMap = new Array();
				
				var html = "";
				if(changeOrders != null && changeOrders.length > 0)
				{
					for(var i = 0; i < changeOrders.length; i++)
					{
						var title = changeOrders[i].title;
						var description = changeOrders[i].description;
						var number = changeOrders[i].number;
						
						html += "<div id=\"co" + i + "\" class=\"" + CO_CLASS_NAME + "\" onclick=\"onClickCo(this);this.blur();\" onmouseover=\"onMouseOverCo(this);\" onmouseout=\"onMouseOutCo(this);\">";
						html += "  <div class=\"" + CO_TITLE_CLASS_NAME + "\" title=\"" + title + " (" + number + "\">" + title + " (" + number + ")</div>";
						html += "  <div class=\"" + CO_DESCRIPTION_CLASS_NAME + "\" title=\"" + description + "\">" + description + "</div>";
						html += "</div>";
						html += "<div class=\"" + CO_SPACER_CLASS_NAME + "\">&nbsp;</div>";
						
						g_coDivToCoMap[("co" + i)] = changeOrders[i];
					}
				}
				coContainer.innerHTML = html;
			}
			function writeCoProperties()
			{
				var changeOrder = g_coDivToCoMap[g_selectedCoDiv.id];	
				var html = "";
				var link = "";
				
				if(changeOrder.properties != null && changeOrder.properties.length > 0)
				{
					for(var i = 0; i < changeOrder.properties.length; i++)
					{
						var name = changeOrder.properties[i].propertyDef.displayName;
						var value = changeOrder.properties[i].value;
						html += "<div><span class=\"" + CO_PROP_NAME_CLASS_NAME + "\" title=\"" + name + "\">" + name + "</span><span class=\"" + CO_PROP_VALUE_CLASS_NAME + "\" title=\"" + value + "\">" + value + "</span></div>"
					}
					link = "http://" + g_settings["server"] + "/AutodeskDM/Services/EntityDataCommandRequest.aspx?Vault=" + g_settings["vault"] + "&ObjectId=" + changeOrder.number + "&ObjectType=ECO&Command=Select";
				}
				
				var doc = System.Gadget.Flyout.document;
				doc.getElementById("tabPageContainer").innerHTML = html;
				doc.getElementById("link").href = link;
			}
			function writeLoginInformation(username, server, vault)
			{
				loginContainer.innerText = username + " - " + server + "\\" + vault;
			}
			
			// Counter implementation
			var g_counterEnabled = false;
			var g_counterValue = 0;
			var g_timerId = -1;
			function startCounter(durationSeconds)
			{
				var interval = (durationSeconds * 1000) / refreshCounterContainer.offsetWidth;
				g_timerId = window.setInterval(onIntervalPassed, interval);
			}
			function setCounterEnabled(enabled)
			{
				g_counterEnabled = enabled;
			}
			function resetCounter()
			{
				g_counterValue = 0;
				refreshCounter.style.width = "0px";
			}
			function stopCounter()
			{
				if(g_timerId > 0)
				{
					window.clearInterval(g_timerId);
					g_timerId = -1;
					resetCounter();
				}
			}
			function onIntervalPassed()
			{
				if(g_counterEnabled == true)
				{
					if(g_counterValue >= refreshCounterContainer.offsetWidth)
					{
						resetCounter();
						refreshCoList();
					}
					else
						refreshCounter.style.width = (g_counterValue += 1) + "px";
				}
			}
			
			// UI Events
			function onClickCo(el)
			{
				if(System.Gadget.Flyout.show)
				{
					if(g_selectedCoDiv.id == el.id)
					{
						System.Gadget.Flyout.show = false;
						g_selectedCoDiv.className = CO_CLASS_NAME;
						g_selectedCoDiv = null;
					}
					else
					{
						setCounterEnabled(false);
						g_selectedCoDiv.className = CO_CLASS_NAME;
						g_selectedCoDiv = el;
						g_selectedCoDiv.className = CO_SELECTED_CLASS_NAME;
						var doc = System.Gadget.Flyout.document;
						writeCoProperties();
					}
				}
				else
				{
					setCounterEnabled(false);
					System.Gadget.Flyout.show = true;
					g_selectedCoDiv = el;
					g_selectedCoDiv.className = CO_SELECTED_CLASS_NAME;
					
					System.Gadget.Flyout.onShow = function()
					{
						writeCoProperties();
					}
					System.Gadget.Flyout.onHide = function()
					{
						if(g_selectedCoDiv != null)
							g_selectedCoDiv.className = CO_CLASS_NAME;
						g_selectedCoDiv = null;
						setCounterEnabled(true);
					}
				}
			}
			function onMouseOverCo(div)
			{
				if(div != g_selectedCoDiv)
					div.className = CO_HOVER_CLASS_NAME;
			}
			function onMouseOutCo(div)
			{
				if(div != g_selectedCoDiv)
					div.className = CO_CLASS_NAME;
			}
			
		</script>
		<style>
			body
			{
				width: 175px;
				height: 240px;
				margin: 2px;
				background-color: #000000;
			}
			.titleContainer
			{
				font-family: Calibri;
				font-size: 18px;
				font-weight: bolder;
				text-transform: uppercase;
				color: #C8C8C8;
				padding-left: 5px;
				padding-right: 5px;
				padding-top: 2px;
				padding-bottom: 2px;
				background-color: #000000;
			}
			.loginContainer
			{
				font-family: Calibri;
				font-size: 9px;
				font-weight: bolder;
				color: coral;
				background-color: #000000;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
			.co
			{
				font-size: 12px;
				font-family: Calibri;
				color: white;
				border-left: 1px solid #303030;
				border-right: 1px solid #303030;
				border-bottom: 1px solid #303030;
				border-top: 1px solid #303030;
				padding-left: 5px;
				padding-right: 5px;
				background-color: #303030;
			}
			.coContainer
			{
				height: 190px;
				width: 171px;
				overflow: auto;
				scrollbar-base-color: #000000;
				scrollbar-face-color: #303030;
				scrollbar-highlight-color: #303030;
				scrollbar-3dlight-color: #000000;
				scrollbar-shadow-color: #303030;
				scrollbar-darkshadow-color: #000000;
				scrollbar-track-color: #303030;
				scrollbar-arrow-color:#000000;
			}
			.refreshCounterContainer
			{
				padding-top:2px;
				width:170;
			}
			.refreshCounter
			{
				background-color: #909090;
				height: 1px;
				width: 0px;
				font-size: 1px;
				padding-top: 0px;
			}
			.coTitle
			{
				font-size: 12px;
				font-family: Calibri;
				color: white;
				width:140px;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
			.coDescription
			{
				font-size: 12px;
				font-family: Calibri;
				color: white;
				width:140px;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
			.coSelected
			{
				font-size: 14px;
				font-family: Calibri;
				color: white;
				border-left: 1px solid #454545;
				border-right: 1px solid #454545;
				border-bottom: 1px solid #454545;
				border-top: 1px solid #454545;
				background-color: #454545;
				padding-left: 5px;
				padding-right: 5px;
			}
			.coHover
			{
				font-size: 14px;
				font-family: Calibri;
				color: white;
				border-left: 1px solid #909090;
				border-right: 1px solid #909090;
				border-bottom: 1px solid #909090;
				border-top: 1px solid #909090;
				padding-left: 5px;
				padding-right: 5px;
				background-color: #303030;
				cursor: hand;
			}
			.coSpacer
			{
				font-size: 2px;
			}
	</style>
	</head>
	<body onload="setupGadget();">
		<div id="titleContainer" class="titleContainer">Vault CO Worklist</div>
		<div id="coContainer" class="coContainer"></div>
		<div id="loginContainer" class="loginContainer"></div>
		<div id="refreshCounterContainer" class="refreshCounterContainer"><span id="refreshCounter" class="refreshCounter"></span></div>
	</body>
</html>

Is there any other changes needed to be made to work with 2009?

 

Message 4 of 6
gluckett
in reply to: Anonymous

Did you get this working with JavaScript?

 

Message 5 of 6
bertha.rios
in reply to: Anonymous

hi, I try to do the same with Vault 2020 but I still having problems to access, did you solve your problem? If you remember how did you do, could you please share your code. Thanks 

Message 6 of 6
bertha.rios
in reply to: bertha.rios

Hello, first of all, thanks to everyone who has shared their knowledge, because thanks to each of you I have managed to understand, even when I am just starting, how to use the vault API. MY program is in typescript, here I share my function to access vault with soap call.
 async loginReadOnly(serverName: string, userName: string, userPass: string, vault: string, host: string): Promise<any> {
    const httpOptions = {
      headers: {
        'Content-Type': 'text/xml; charset=utf-8',
      },
    };

    let body =
      '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">' +
      '<Header>' +
      '<SecurityHeader xmlns="http://AutodeskDM/Services">' +
      '<Ticket>0</Ticket>' +
      '<UserId>0</UserId>' +
      '</SecurityHeader>' +
      '</Header>' +
      '<Body>' +
      '<SignInReadOnly xmlns="http://AutodeskDM/Filestore/Auth/1/7/2019/">' +
      '<dataServer>'+serverName+'</dataServer>' +
      '<userName>'+userName+'</userName>' +
      '<userPassword>'+userPass+'</userPassword>' +
      '<knowledgeVault>'+vault+'</knowledgeVault>' +
      '</SignInReadOnly>' +
      '</Body>' +
      '</Envelope>';
    return this.httpService
      .post(
        'http://'+host+'/AutodeskDM/Services/Filestore/v25/AuthService.svc',
        body,
        httpOptions,
      )
      .pipe(map((res) => res.data));
  }

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report