hide print button based on no of clicks in producs module

need to hide print option in module based on no of clicks eg : if a user clicks the print option 5 times then the print option should be disabled for the user how can this be achieved thanks…

';
echo $q;
echo $no_done;
$sql = "UPDATE `users_cstm` SET `used_prints_c`='".$no_done."' WHERE `id_c`= '".$u_id."'";
    $res = $this->bean->db->query($sql); // should work only on clicking the print button 

/// but its beeing executed on page load of detail view even without clcking the print button

i thought of doing it in ajax call incustom js like this cani achieve this through entry point access file and update uers print functionality?

<?php if(!defined('sugarEntry'))define('sugarEntry', true); require_once ('include/entryPoint.php'); global $DB, $current_user; $u_id=$current_user->id; $no_done=$current_user->used_prints_c; $no_done=$no_done+1; //$sql = "UPDATE `users_cstm` SET `used_prints_c`='".$no_done."' WHERE `id_c`= '".$u_id."'"; $status = $DB->query("UPDATE `users_cstm` SET `used_prints_c`='45' WHERE `id_c`= '".$u_id."'"); if($status == false) { die("Didn't Update"); } please need help can you suggest asap would be great thanks

i sorted it out myself it can be achieved through ajax call and entry point in sugarcrm

B)

@mohammadyaseer

I am glad you managed.

Could you please share your complete solution to allow others to benefit from it also?

Thx!!!

Yeah Sure !!!

I created a two fields in user management module and with

  1. no of prints used
  2. No of prints .

then go to respective module and add js file detailview defs
as my need was for invoices :

'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom/modules/AOS_Invoices/print_dependent.js',
        ),
      ),

And the following ajax call for sugar entry … and create an entry point call in js(How to create an entry point can be googled easy to find).

$(document).ready(function(){

//alert("Hello yaseer entry point");
    $("#print_order").click(function(){
        $.ajax({
		   url: 'http://your ip(web)/index.php?entryPoint=MyTimeEntryPoint',
		   error: function() {
		      alert('<p>An error has occurred</p>');
		   },
		   success: function(data) {
			//alert(data);
		   },
		   type: 'GET'
		});
    });
});

inside entry point php file you can add the following code :

<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once ('include/entryPoint.php');

global $DB, $current_user;
    //$no_done = = intval($_GET['q']);
$conn = mysqli_connect("localhost","user_name","password,"suite_db");
        $u_id=$current_user->id;
       $no_done=$current_user->used_prints_c;
        $no_done=$no_done+1;
        $sql = "UPDATE `users_cstm` SET `used_prints_c`='".$no_done."' WHERE `id_c`= '".$u_id."'"; //update the values of users print used in invoice into users module 
        //$res =$this->bean->db->query($sql);
        if ($conn->query($sql) === TRUE) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . $conn->error;
        }

ANd at LASt : add the code into detailview.php in custom folder :

//hide the print button based on no of clicks invoices ... 
global $current_user;
    	$no=$current_user->no_of_prints_c;
    	$no_done=$current_user->used_prints_c;
	
	if($no<$no_done)
	{
	echo "<style>
		#print_order {
		display: none;
		};
		</style>";
		echo "print exceeded Thank You!!";
	}

If any Better Solutions available is appreciated As i am a student working for a company for my pocket money !! Thanks… :wink:

i need one more help it would how to populate custom relate field popup as display in image:
eg : In module case i have two sub panels tasks and working staff receptively
in working staff i have a relate field called SELECT TASK where i can select tasks but i need the popup from that relate field to be displayed with the tasks related to same parent case information ( case has task1, task2 should display only task1 and task2 inside relate field popup ) how can i achieve it i dont find any particular file for this popup thanks any advice and documentation would be helpful Thanks

Please can i get by default like this popup from relate field thanks!!

Im glad your code worked out fine for you but you really need to look into Beans. The way you have implemented DB connection and Queries is not a good practice per se.
Sugar Beans manage all your insert/select/delete queries and are way easier than raw SQL.
Also in your ajax call you do not need to specify the absolute URL, that will cause issues in case your domain changes and your ajax will no longer work.
Just “index.php?entryPoint=xyz” will suffice.