How to Add contextmenu on button click

How to Add contextmenu on button click please help
code:

$("Button",
          {
         alignment: go.Spot.TopRight,
         click: function (e, button) {
           //  alert("cfdfd");
             $(go.TextBlock, textStyle(),
            {
                margin: 8,
                maxSize: new go.Size(160, NaN),
                wrap: go.TextBlock.WrapFit,
                editable: false,
            }),
            {
                toolTip:  // define a tooltip for each node that displays the color as text
                  $("ToolTip",
                    $(go.TextBlock, { margin: 4 },
                      new go.Binding("text", "text"))
                  ),
                contextMenu: partContextMenu// end of Adornment
            }
         } // this function is defined below
     }

Your click function creates a TextBlock and throws it away. Then it creates a JavaScript Object, sets two properties on it, and then throws it away.

If you have set contextMenu on the Node

$(go.Node,
    { contextMenu: ... },
    ...

then your Button click function could be:

function(e, button) {
  e.diagram.commandHandler.showContextMenu(button.part);
}

Sir, Am unable to add this in the code as it gives error.(command error is not defined).am attaching the code please do the needful

myDiagram.nodeTemplateMap.add("",
(go.Node, "Table", nodeStyle(), (go.Panel, “Auto”,
(go.Shape, "Rectangle", { desiredSize: new go.Size(80, 50), fill: yellowgrad, stroke: "black", portId: "Out"}, new go.Binding("figure", "figure"), new go.Binding("fill", "color")), (go.TextBlock, textStyle(),
{
margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: false
},
{
toolTip:
("ToolTip", (go.TextBlock, { margin: 4 },
new go.Binding(“text”, “text”))

                  ),
                contextMenu: partContextMenu
            },
           
            new go.Binding("text").makeTwoWay())),
        // four named ports, one on each side:
        makePort("T", go.Spot.Top, go.Spot.TopSide, false, true),
        makePort("L", go.Spot.Left, go.Spot.LeftSide, true, true),
        makePort("R", go.Spot.Right, go.Spot.RightSide, true, true),
        makePort("B", go.Spot.Bottom, go.Spot.BottomSide, true, false),
         $("Button",
          {
         alignment: go.Spot.TopRight,
         click: function (e, button) {
             //  alert("cfdfd");
            
             $(go.TextBlock, textStyle(),
            {
                margin: 8,
                maxSize: new go.Size(160, NaN),
                wrap: go.TextBlock.WrapFit,
                editable: false,
            }),
            {
                toolTip:  
                  $("ToolTip",
                    $(go.TextBlock, { margin: 4 },
                      new go.Binding("text", "text"))
                  ),
                contextMenu: partContextMenu// end of Adornment
            }
             e.myDiagram.commandHandler.showContextMenu(button.part);
         } 
     },
          $(go.Shape, "Ellipse", { width: 8, height: 8 }))

  
     ));

Make the changes that I showed you in my previous reply.

sir I am getting this error
commandHandler is not defined
e.myDiagram.commandHandler.showContextMenu(button.part);

In the debugger you will see that e.myDiagram is undefined. Is there a reason you didn’t want to follow my suggestion?