0

I've a custom javascript button, to update the field on same object. this is perfect working for admin user but not working for non admin user.

Code as;

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

if("{!Patient_Services__c.Service_Invoiced__c}"== "0" ) 
{
    if("{!Patient_Services__c.Who_to_Invoice__c}"=="Facility Account")
        {

                var c = new sforce.SObject("Patient_Services__c"); 
                c.id = "{!Patient_Services__c.Id}"; 
                c.Ready_for_Billing__c= "1"; 
                result = sforce.connection.update([c]); 
                window.location.reload();

        }
}

i'm try on profile finance user(not admin). The following permission for ready for billing field and object

Profile Permission for object; not given any access.

Permission set for object(User) : Read, Create, Edit, View All

Field accessibility for field : visible to page layout and profile.

when i click on custom button, the page is refreshed but field is not update. Please suggest.

6
  • I know that you said that the field access for the field is visible for the profile (and I assume also not read only), but double check to make sure that they have visibility to ALL of the fields, even the ones in the IF statements, and make sure that none of the fields they are setting to a value are marked read only. Since a button like this won't display any VRs on page if there are errors, try logging in as the user and manually doing what the button does automatically, see if any VRs or Proc Builders are stopping the user. Commented Jul 25, 2016 at 12:10
  • Which error occurred for other user click in this button. Can you please add the error message? Commented Jul 25, 2016 at 12:30
  • @MSCB. no error is occur. when i click on custom button, the page is refreshed but field is not update. thats means code is executed.
    – Amol
    Commented Jul 25, 2016 at 12:49
  • Print your result. add this code console.log("result:::",result); //window.location.reload(); your result is passed or failed is print in your console logs. Commented Jul 25, 2016 at 12:57
  • Are you try to catch error message? @Amol Commented Jul 27, 2016 at 7:47

1 Answer 1

1

As you are saying all object permissions are present for the user, please check if the user has API permission available.

To function the OnClick JavaScript button permission the profile should have this permission enabled.

You can check this by going to Setup -> manage users -> profiles -> Under the "Administrative Permissions" area --> "API Enabled" check box.

Also you should update your code as below to capture the error message and display it as alert message. Based on the error message you can fix the issue.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")}
if ("{!Patient_Services__c.Service_Invoiced__c}" == "0") {
    if ("{!Patient_Services__c.Who_to_Invoice__c}" == "Facility Account") {

        var c = new sforce.SObject("Patient_Services__c");
        c.id = "{!Patient_Services__c.Id}";
        c.Ready_for_Billing__c = "1";
        var result = sforce.connection.update([c]);
        if (result[0].getBoolean('success')) {
            alert('success!'); //Just for testing, You can remove this
            window.location.reload();
        } else {
            alert('An error occurred updating this record:\n\n' + result[0].errors.message);
        }
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .