function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chandra babu 2Chandra babu 2 

how two su of two column fields and Display the calculated values in another column?

Amount  :
Discount :

Net Price:

I need i will give Amount value and Discount values But on UI page Directly calculated that two column fields ,and display the net price total value.

please tel me how to create  and display values. 
Best Answer chosen by Chandra babu 2
☯ BonY ☯☯ BonY ☯
Hi Chandra,

try this code...

vf page:
<apex:page standardController="purchase__c" extensions="Hello">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1"  >
                <apex:inputField value="{!purchase__c.name}">
                </apex:inputField>
                <apex:inputField value="{!purchase__c.Amount__c}">
                    <apex:actionSupport event="onkeyup" action="{!action}" reRender="dynamic"/>
                </apex:inputField>
                <apex:inputField value="{!purchase__c.Discount__c}">
                    <apex:actionSupport event="onkeyup" action="{!action}" reRender="dynamic"/>
                </apex:inputField>
                <apex:outputPanel id="dynamic">
                    <apex:outputLabel > Net Price : </apex:outputLabel>
                    <apex:outputLabel > {!theText}</apex:outputLabel>
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
apex cls : 
 
public class Hello {
    public String theText {get;set;}
    purchase__C p1;
    public hello(ApexPages.StandardController con) 
    {
        p1=(purchase__c)con.getRecord();     
        
    }    
    public PageReference action() {
        decimal a,b;
        a = p1.amount__c;
        b = p1.discount__c;
        if(a == null)
            a = 0;
        if(b == null)
            b = 0;
        theText = string.valueof(a + b);
        return null;
    }
}

 

All Answers

Ajay K DubediAjay K Dubedi
Hi Chandra,
You can a create a custom formula field that will store the calculated price and show it on the Vf page you want just by querying.On page layout remove this field from the page layout.

Thanks .
Gyanender SinghGyanender Singh
Hi Chandra,

You can use formula field for the net price like:

For this i created two currency type field Amount and Discount and a formula field Ner Price and the formula field is:
amount__c-(( amount__c * discount__c )/100) and in this you get the net price on the detail UI page.
Suppose that you have 100 rupees Amount and 20 rupees Discount so you get the 80 rupees as the Net Price.
Chandra babu 2Chandra babu 2
hi Gyanender sing Thanks for giving your answer.   I can give the values amount and Discount it will be display on Detail page ,not on UI page,so please tel me how to display on UI page.
Chandra babu 2Chandra babu 2
i want to display the UI page only.pls tel me very fast.
 
Chandra babu 2Chandra babu 2
hi singh i ned to display the only on UI page pls tel me
 
Gyanender SinghGyanender Singh
formula fields comes only on the detail UI Page not on the edit page..

please confirm me you are want this field on the vf page or object UI(page layout).
Chandra babu 2Chandra babu 2
User-added image
Chandra babu 2Chandra babu 2
i will give amount and Discount values But i nedd calculate the net price value pls tel me
 
Gyanender SinghGyanender Singh
this is a vf page?? there is not any button in the vf page ,if this is a vf page so first you have to save records and query the formula field in the controller and show the formula field in the vf page.
Chandra babu 2Chandra babu 2
Then how to Display the Net price value pls tel me Singh
 
Chandra babu 2Chandra babu 2
i am not put in the any Button ,incase i had put Save Button ,when click on Save Button Todisplay the netprice value on detail page,i need Display Here only,then how it is possible pls tel me Singh.
 
Gyanender SinghGyanender Singh
Send me your controller and vf page code..
Chandra babu 2Chandra babu 2
my ttask is Directly Display on netprice value.so plese tel me
 
Chandra babu 2Chandra babu 2
i need only on  Displsy vf page 
Chandra babu 2Chandra babu 2

Apex class
==================
public class purchase

{
public purchase__c purca{get;set;}
public list<purchase__c> getper{get;set;}

public  purchase()
{
getper=new list<purchase__c>();
}

public pageReference clas()
{
string M=Apexpages.currentpage().getparameters().get('chand');

getper=[select  Name,Amount__c,Discount__c,Net_price1__c from purchase__c where Name=:M];
return null;

 }
 }
vf page
===================
<apex:page controller="purchase">
<script>
function CalculateAmount()
      {  
        
         var Price =  VALUE(Amount__c);
         var Qty = VALUE(Discount__c);
         
         var Amount =  Price - Qty;      
      
         VALUE(Net_price1__c) = Amount;
      }
</script>


  <apex:form id="fm">
  
      <apex:pageBlock id="pb">
      <apex:pageBlockSection id="pbs" columns="1" >
       
       <apex:inputField id="Price" value="{!purca.Amount__c}" ></apex:inputField>
  <apex:inputField id="Sold" value="{!purca.Discount__c}"  onkeyup="javascript&colon;CalculateAmount();"> </apex:inputField>  
  <apex:inputField id="Sale" label="net Price" value="{!purca.Net_price1__c}" onchange="CalculateAmount();"></apex:inputField>
  </apex:pageBlockSection>
             
             
      </apex:pageBlock>
  </apex:form>
</apex:page>
Chandra babu 2Chandra babu 2
code is no errors but how to fallow the way i dont no.So could you pls tel me.where to adding and how to adding.
Gyanender SinghGyanender Singh
User-added image
if you want this result than using the following code:

public class purchase{
    public account purca{get;set;}
    public list<account> getper{get;set;}
    string M=Apexpages.currentpage().getparameters().get('id');
    
    public  purchase(){
        getper=new list<account>();
        getper=[select  Name,Amount__c,Discount__c,Net_price__c from account where Amount__c != null];
    }


}

<apex:page controller="purchase">
    <apex:form >
       
            <apex:repeat value="{!getper}" var="aa">
                <apex:outputLabel value="Amount" />
                &nbsp;&nbsp;&nbsp;&nbsp;
                <apex:inputField value="{!aa.amount__c}" id="theValue1" /><br/>
                <apex:outputLabel value="Discount"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <apex:inputField value="{!aa.discount__c}" id="theValue11"/><br/>
                <apex:outputLabel value="Net Price"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <apex:outputText value="{!aa.Net_Price__c}" id="theValue1111"/><br/>
                
            </apex:repeat>
        
    </apex:form>

</apex:page>
Gyanender SinghGyanender Singh
Hi Chandra,

What is your issue Resolved ??
So don't forget this as a Best Answer..

Thanks Gyani....
☯ BonY ☯☯ BonY ☯
Hi Chandra,

try this code...

vf page:
<apex:page standardController="purchase__c" extensions="Hello">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1"  >
                <apex:inputField value="{!purchase__c.name}">
                </apex:inputField>
                <apex:inputField value="{!purchase__c.Amount__c}">
                    <apex:actionSupport event="onkeyup" action="{!action}" reRender="dynamic"/>
                </apex:inputField>
                <apex:inputField value="{!purchase__c.Discount__c}">
                    <apex:actionSupport event="onkeyup" action="{!action}" reRender="dynamic"/>
                </apex:inputField>
                <apex:outputPanel id="dynamic">
                    <apex:outputLabel > Net Price : </apex:outputLabel>
                    <apex:outputLabel > {!theText}</apex:outputLabel>
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
apex cls : 
 
public class Hello {
    public String theText {get;set;}
    purchase__C p1;
    public hello(ApexPages.StandardController con) 
    {
        p1=(purchase__c)con.getRecord();     
        
    }    
    public PageReference action() {
        decimal a,b;
        a = p1.amount__c;
        b = p1.discount__c;
        if(a == null)
            a = 0;
        if(b == null)
            b = 0;
        theText = string.valueof(a + b);
        return null;
    }
}

 
This was selected as the best answer
Chandra babu 2Chandra babu 2
hi singh if not like that i need only give the values on vf page and display the net price.i need that type.
Chandra babu 2Chandra babu 2
Thanq Boni