How to add a Button/Link to a representation to call a method?

2 minute read time.

Previously, I talked about a basic example of V7 Style coding here, and a question was asked, on how to add a button with method to a representation and I like to show a basic example of that here.
Before we get to the point of this blog, please review an online help entry titled, “Tip distinction between methods and operations and working in a stateless context” which is accessible in Sage X3 online help by searching for the title.





Based on the above online help entry you would learn what is the difference between a method vs an operation.

Now to the point of the example, here, I am going to add a button/link to my representation that will call a method with an information message also, another button that will call an operation.  (If you need to know how to create the ZCLIENT example review the first blog)


  1. Open Development, Data and Parameters, Classes , Classes.
  2. Select ZCLIENT class.
  3. Go to Methods tab, and create a new line like below.




  4. Save and Validate.
  5. On the General tab, notice the name that is assigned to your class code.




  6. Open Development, Scripts Dictionary, Scripts, Script Editor.
  7. Enter the name of your Class script.
  8. Add the following Code.



    ################

    $METHODS
    Case [L]CURPTH
       When ""
          Case [L]ACTION
       When "ZINFORMATION"
              Gosub SHOW_INFORMATION
       When "ZLISTINFORMATION"
              Gosub SHOW_INFORMATION_OPERATION
       
          Endcase
    Endcase
    Return


    $PROPERTIES
    Case [L]CURPRO
    Endcase
    Return

    ######################

    $SHOW_INFORMATION

    [L]ASTATUS = fmet this.ASETERROR("", "This is a Method", [V]CST_AWARNING)  ## this will show  a message that this is a method

    Return

    ##########
    $SHOW_INFORMATION_OPERATION

    [L]ASTATUS = fmet this.ASETERROR("", "This is an Operation", [V]CST_AWARNING) ## this will show  a message that this is an Operation

    Return



  9. Save and Compile.
  10. Open Development, Data and parameters, Classes, Representations.
  11. Select ZCLIENT representation.
  12. Click on Links Tab.
  13. For the Anchor type select Record.
  14. Add a new link like below.








  15. The above is for a method link.
  16. Below is an example of operation link.










  17. Save and validate.
  18. Now when you launch your representation, in the query mode I have a link that point to my operation.






  19. By clicking on the link I would have the message as I expected.




  20. Similarly on the edit facet, I have my Method link.






  21. By clicking on this link I would have below.







Conclusion:


You can add a link  to a representation and add code for it to call a method.

What is next:

In future blogs I will be talking about how you can manage two tables like a header and line, so stay tune for that