Skip to main content
Babu BaDi a posé une question dans #Data Management
I would like to disable custom javascript button on page layout until the status of record is set to "Closed". If the status is closed then only enable so users can click on it.. if there is a status other than closed then keep the button disabled...currently by clicking the button I am changing status to NEW which is working fine..Below is my code..

 

----

{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

try{

if("{!Pims__c.Status__c}" !== "New"){

var isContinue = confirm("You're about to reopen the record. Continue ?");

if(isContinue){

var Pims = new sforce.SObject("Pims__c");

Pims.Id = "{!Pims__c.Id}";

Pims.Status__c = "New";

Pims.Reopened__c = "Yes";

var result = sforce.connection.update([Pims]);

if(result[0].success === "true"){

location.reload();

}

else{

alert(

"An Error has Occurred. Error: \r\n" +

result[0].errors.message

);

}

}

}

else{

alert(

"This record has been reopened!"

);

}

}

catch(e){

alert(

"An unexpected Error has Occurred. Error: \r\n" +

e

);

}

 

 
9 réponses
  1. 18 déc. 2014, 18:08

    This one:

    {!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

    try {

    if (

    "{!$Profile.Name}" !== "Building Plan Reviewer" &&

    "{!Pims__c.Status__c}" !== "New" &&

    "{!Pims__c.Status__c}" !== "Closed"

    ) {

    var isContinue = confirm("You're about to reopen the record. Continue ?");

    if (isContinue) {

    var Pims = new sforce.SObject("Pims__c");

    Pims.Id = "{!Pims__c.Id}";

    Pims.Status__c = "New";

    Pims.Reopened__c = "Yes";

    var result = sforce.connection.update([Pims]);

    if (result[0].success === "true") {

    location.reload();

    } else {

    alert(

    "An Error has Occurred. Error: \r\n" +

    result[0].errors.message

    );

    }

    }

    } else {

    alert(

    "This record has been reopened!"

    );

    }

    } catch (e) {

    alert(

    "An unexpected Error has Occurred. Error: \r\n" +

    e

    );

    }

0/9000