Don't find document or assignements when right click on task

Hi everyone,

I have a task like that (sorry it's in french) :

I want to add a button in the right click menu only if the task contains a file.

I know how to add a button on right click and how to hide it when I want. But, I failed to know if the task have a file.

This is what I use actually:

// function called when creating right click menu
shellListing.Events.Register(Event_ShowContextMenu, function (selectedItems) {
    if(selectedItems.Count == 1 && selectedItems.ObjectVersions.Count == 1) { // check if there is a document, never true when right clic on task. That's my issue
	    var objVerSelected = selectedItems.ObjectVersions[0];
		var vault = shellFrame.ShellUI.Vault; // get vault
	    if(objVerSelected.HasAssignments && vault.ClassOperations.GetObjectClass(objVerSelected.Class).ObjectType == 10) { // check if it's a task
	        // I want to show it
	    } else {
	        // don't want to show it
	    }
    }
});

In my code, the task verfification (to check the Type object) work perfectly. The way to get file work when you right click on document but not when on a task link to document.

Also, `HasAssignments` is always false.

How can I do ?

  • I am posting this message for others who find this; Mathis and I spoke in a different medium and resolved the issue.

    Key here is to realise that the assignment does not contain a file at all; it is related to an object.  The question becomes how to identify these relationships.

    There's a number of ways to do this but perhaps the most easy-to-use is the GetRelationships method in the API.  This takes an ObjVer and information on the types of relationship to load, and returns the related objects.  This may need to be filtered by the type of object you need, but should indicate the relationships from this object to others.

    Another approach would be to use the property value on the selected object.  This is better in some ways, as the data is probably already available for you.  In this way you could:

    1. Load the ObjType from M-Files API for the "document" built-in object type.
    2. Identify the default property definition.  This is the one used to make relationships to objects of this type.
    3. Check whether the selected object has a value for that property definition.  If it does not then it has no relationships.  If it does, then check the count of items in the multi-select-lookup property; if it's non-zero then it has relationships to documents.

    Regards,

    Craig.