0

I want to change the label of a javascript button based on the field value on a custom object. I tried implemented using the solution provided in the below link however not successful. There is no change in the button name. Can anyone please guide me?

How to change label on custom button based on value in the record being displayed?

1

JavaScript buttons now require a button click before they execute at all. Some basic logic has changed as a result of this. If you want to change the button, you can do so, but only after the user clicks the button. The basic script for this looks like:

document.querySelectorAll("[name="+element.name+"]").forEach(
  input => input.title = input.value = "Hello World"
);

If you want to change the label when the page loads, you can do so with record types and page layouts, but the values will still be hard-coded to whatever specific values you configure.

There may be another way to do whatever it is you're trying to do, but the technique outlined in the previous question/answer will not work.

  • I don't want to create additional record types, rather would want to do programmatically. I do not have much experience on html. Could you please provide me an example? – Kanikala Feb 19 '18 at 6:13
  • @Kanikala As I said, you cannot do so except after they click the button. The code above works. You cannot use the "execute on page load" trick any more, as it has been intentionally blocked by Salesforce. – sfdcfox Feb 19 '18 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.