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
NasirNasir 

how to make field read only when the field which is picklist changes to other value

Hi,

 

Please  find the solution.

 

Actually there are two custom fields

1:payment date

2:invoice status

 

where payment date is a date field and invoice status is a picklist field which has the picklist values 'approved,onhold and paid.'

When invoice status=paid 

then payment date should be editable 

but when invoice status =onhold or approved.

payment date should not be editable

 

what i had done in this,i had created a new record type for which payment date is editable,and i had created a new page layout .then i had written a workflow for this.but this is not working.

 

Please advice

 

Thanks

 

SargeSarge

Hi Nasir,

 

It is not possible to suddenly change the standard pagelayout, hence I would like to see the requirement in different view.

> When Invoice Status == Onhold or approved, changes made to payment date are not valid.

 

So there are two ways of achieving this

1) Validation rule to throw an error when Payment Date changes during Invoice status onhold, approved

     AND( OR(ISPICKVAL(Invoice_Status__c, "Onhold") , ISPICKVAL(Invoice_Status__c, "Approved")), ISCHANGED(Payment_Date__c))

2) Trigger :

       Undo the changes on payment date if Invoice Status finally comes to onhold, approved

 

 

Trigger undoPaymentDateChanges on Custom_Object__c(before update){

          for(integer i=0; i< trigger.new.size(); i++)[
                 if(trigger.new[i].Invoice_Status__c != trigger.old[i].Invoice_Status__c && (Trigger.new[i].Invoice_Status__c == 'Onhold' || trigger.new[i].Invoice_Status__c == 'Approved')){

                             trigger.new[i].Payment_Date__c = trigger.old[i].Payment_Date__c;

                  }

         }

   }

 

 

NasirNasir

Thanks

 

It worked well.but validation rule restrict us when invoice status is approved or onhold. Can it be done by creating a page layout and recordtype in which payment date is read only when invoice status is approved or onhold?i mean when i select invoice status to approved or onhold,there a different pagelayout should come where payment date cannot be changed.