Display Count of your Opportunities against Company

By | November 16, 2016

In my previous blog, I have explained how to display Current User Name under custom tab. Here, I am going to explain how to display the count of records (say Opportunities) which are in progress and assigned to me i.e. Current Logon User against respective companies using jQuery mechanism.

New Stuff: Event Management in Sage CRM

To see the above functionality, refer the below steps.

1. Prepare a .js file with following code –

crm.ready(function()
{
if (crm.getArg(“Key0”) == “1”)
{
var OppoAssignUserCount=””;

if(document.getElementById(“HDNCount1”))
{
OppoAssignUserCount = document.getElementById(“HDNCount1”).value;
if(OppoAssignUserCount==”” || OppoAssignUserCount==”null” || OppoAssignUserCount ==”undefined”) OppoAssignUserCount=”0″;
}
$(“td.TABOFF:contains(‘Opportunities’),td.TABON:contains(‘Opportunities’)”).text(“Opportunities (” + OppoAssignUserCount + “)”);
}
});

2. Give the path of your Custom Page in the Custom Content Box. Also, copy the below code and paste it in the create script of Company Name field of “CompanyBoxLong” screen. Refer Below Snapshot.

var sCompanyId=new String(Values(“Comp_CompanyId”))
if(sCompanyId==”null”||sCompanyId==”undefined”||sCompanyId==””)
{
sCompanyId=new String(FormValues(“Comp_CompanyId”))
if(sCompanyId==”null”||sCompanyId==”undefined”||sCompanyId==””)
{
sCompanyId=new String(CRM.GetContextInfo(‘company’,’Comp_CompanyId’))
if(sCompanyId==”null”||sCompanyId==”undefined”||sCompanyId==””)sCompanyId=”0″;
}
}

var User_ID = CurrentUser.user_userid;

var sPrimaryUserSQL=”select Oppo_AssignedUserId,Count(*) as OppoCount from Opportunity(nolock) where oppo_deleted is null and Oppo_PrimaryCompanyId=”+sCompanyId+” and Oppo_AssignedUserId=”+User_ID+” and Oppo_Status=’In Progress’ group by Oppo_AssignedUserId”;
var RecPrimarySQL=eWare.CreateQueryObj(sPrimaryUserSQL);
RecPrimarySQL.selectSQL();

if(!RecPrimarySQL.eof)
{
Count1=RecPrimarySQL(“OppoCount”);
if(Count1==”null”||Count1==”undefined”||Count1==””)Count1=”0″;
Count1=parseInt(Count1);
}
else{ Count1=”0″;}

Caption+=”Company Name:<input type=’hidden’ id=’HDNCount1′ name=’HDNCount1′ value='”+Count1+”‘>”

Image01

3. Repeat above steps under opportunity entity as well. See below snapshot.

Image04

 

4. After saving this, you will be able to see the effect as shown below.

Image02

Image03

Happy Scripting..!!

Also Read:

1. Changing max allowable length of Text field using Jquery
2. Sort Dropdown list items using jQuery
3. Apply underline to a Column Header in List or Grid
4. Displaying date fields in Nonstandard formats
5. Linked selection fields through client side scripting