Using the COM Graphic Object in a Create Script within Sage CRM screens

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Using the COM Graphic Object in a Create Script within Sage CRM screens

  • Comments 2
  • Likes

An on Premise Sage CRM customer had the the requirement to display the Opportunity Certainty data graphically.

This can be achieved using the GraphicBlock object to create a graphic that can then be displayed by the Caption property of the field.

You can learn more about the graphic object in the online Developer Guide.

The script in the image above has been added to the OpportunityStatusBox which belongs to the OpportunityProgress table.

The javascript below was then added to the create script of the oppo_certainty field.


var strCertainty=CRM.GetContextInfo('opportunity','oppo_certainty'); 
var graphic;
graphic=CRM.GetBlock('graphic'); 
graphic.DisplayForm = false;
graphic.Border=1;
graphic.ImageWidth=100;
graphic.ImageHeight=20;
graphic.Animation('Add','1');
graphic.ImageWidth=strCertainty;
graphic.ImageHeight=20;
graphic.GradientFill('Blue','Blue','LeftToRight');
graphic.TextOut(40,1,strCertainty+'%',true); 
graphic.Animation('Add','100');
Caption = CRM.GetTrans("colnames","oppo_certainty")+":"+graphic.Execute();
CaptionPos = 3;

The main advantage of building a graphic using the Create script is that it allows you complete freedom to access data from within Sage CRM and use any other of the API calls in javascript that you might need.

Comments
  • This is interesting to see in your example a graphic like a rectangular box with color filled, any chances of an animated image such as a GIF in round/circular shape?

  • Kannan

    The COM object does have methods that allow round images (or any line shape) to be drawn but these are not the simplest to use.  e.g.

    var graphic = CRM.GetBlock('graphic');

    graphic.ImageWidth=100;

    graphic.ImageHeight=100;

    graphic.Ellipse(1,1,100,100);

    CRM.AddContent(graphic.Execute());

    Response.Write(CRM.GetPage());

    If you are dealing with more complex graphic shapes like pie charts, then you maybe better advised to use Sage CRM's Charting objects, or a third party utility such as Fusion Charts or Google Charts.  I will post something about using Google Charts tomorrow.