VBScript - Trying to calculate a Project Percentage

Hey,

I'm trying to calculate a percentage of a project's completion through completed assignments,

I need a VBScript get a count of completed assignments related to a an object and total assignments related to a an object then I can calculate a percentage from there.

Anyone got any ideas?

  • Option Explicit
    ' Specify the object ID for which you want to retrieve related objects
    Dim objectID
    objectID = 101 
    
    ' Get the object version
    Dim objVersion : Set objVersion = vault.ObjectOperations.GetObjectInfo(objectID)
    
    ' Get the object's related objects
    Dim relatedObjects : Set relatedObjects = vault.ObjectOperations.GetRelatedObjects(objVersion.ObjVer)
    

    This is what I've started, I get a type mismatch for the GetObjectInfo.

  • yeah figured that out am pretty new to all this, so am fumbling my way through it.

  • If anyone is still interested, this is what i ended up doing, it works, but has some issues because the project property isn't always filled in on the assignment, i plan to update it with a search for related objects rather than a object conditional search, but I did this in an hour or so and it works well enough for what i needed.

     Option Explicit
    '-----------------------GetProperties of current object----------------------------
    Dim oPropVals : Set oPropVals = Vault.ObjectPropertyOperations.GetProperties (ObjVer,False)
    
    '------------------------------------Variables-------------------------------------
    Dim PDClass: PDClass = 100 'built in Class property definition
    
    '-------------------------------Project Variables---------------------------------
    Dim OIDProject: OIDProject ='Project object id
    Dim CIDProject: CIDProject = 'Project class id
    Dim PDProject: PDProject = 'Project property definition
    
    '-------------------------------Assignment Variables---------------------------------
    Dim OIDAssignments: OIDAssignments = 'Assignments object id
    Dim CIDAssignments: CIDAssignments = 'Assignments class id
    Dim PDAssignments: PDAssignments = 'Assignments property definition
    Dim PDCompleted: PDCompleted = 'built in Completed property definition
    
    
    '----------Searching for Assignments object with project as selected------------
    
    ' Search For Assignments
    Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions") 
    
    'Define object you are searching for 
    Dim oSCClass: Set oSCClass = CreateObject("MFilesAPI.SearchCondition") 
    oSCClass.ConditionType = MFConditionTypeEqual
    oSCClass.Expression.SetStatusValueExpression MFStatusTypeObjectTypeID, nothing '
    oSCClass.TypedValue.SetValue MFDatatypeLookup, OIDAssignments ' Object ID of assignments
    oSCs.Add -1, oSCClass
    
    'Define Search Condition for project
    Dim oProjectCondition: Set oProjectCondition = CreateObject("MFilesAPI.SearchCondition")  	'create a search condition
    oProjectCondition.ConditionType = MFConditionTypeEqual          		' left side must equal right side
    oProjectCondition.Expression.DataPropertyValuePropertyDef = PDProject   	' left side use the property id 
    oProjectCondition.TypedValue.SetValue MFDatatypeMultiSelectLookup, ObjVer.ID 'Right Side use the current object id
    oSCs.Add -1, oProjectCondition 'add condition to search
    
    ' Search for just the non deleted element
    Dim oSearchNonDeleted: Set oSearchNonDeleted = CreateObject("MFilesAPI.SearchCondition") 
    oSearchNonDeleted.ConditionType = MFConditionTypeEqual
    oSearchNonDeleted.Expression.DataStatusValueType = MFStatusTypeDeleted
    oSearchNonDeleted.TypedValue.SetValue MFDatatypeBoolean, False
    oSCs.Add -1, oSearchNonDeleted	
    
    ' Execute Search
    Dim oSearchResults: Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSCs,MFSearchFlagNone, True) 
    
    'add another condition for completed property defintion being true
    Dim oCompletedCondition: Set oCompletedCondition = CreateObject("MFilesAPI.SearchCondition")  	'create a search condition
    oCompletedCondition.ConditionType = MFConditionTypeEqual          		' left side must equal right side
    oCompletedCondition.Expression.DataPropertyValuePropertyDef = PDCompleted   	' left side use the property id 
    oCompletedCondition.TypedValue.SetValue MFDatatypeBoolean, true
    oSCs.Add -1, oCompletedCondition
    
    're-execute search
    Dim oSearchResultsCompleted: Set oSearchResultsCompleted = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSCs,MFSearchFlagNone, True) 
    
    '------------------calculate percentage with the two values------------------
    Dim Result
    Dim sIsNull
    Dim iTotal: iTotal = oSearchResults.Count
    Dim iCompleted: iCompleted = oSearchResultsCompleted.Count
    
    if oSearchResults.Count >= 1 Then
    	Dim iDecimal: iDecimal = iCompleted / iTotal
    	Dim iPercentage: iPercentage = iDecimal * 100
    	iPercentage = Round(iPercentage,2)
    	output = CStr(iPercentage) + "%"
    End If