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
UrvikUrvik 

Javascript Button Help

Hi,
I have the following jscript button. It checks the users permission set and work accordingly but it requies user to have "View Setup and Configuration" permission at the user level. We have users without that permission and not able to submit the records. Can someone please assist how to make this button work without assigning "View Setup and Configuration" permission to users? I am getting the following error.
User-added image
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
try {
    var result = 
        sforce.connection.query(
            "SELECT Id " +
            "FROM PermissionSetAssignment " +
            "WHERE PermissionSetId = '0PSK00000004T11' " +
            "AND AssigneeId = '{!$User.Id}'"
        );

    var psAssignment = result.getArray("records");
    if (
        "{!Pims__c.Status__c}" !== "Under Review" &&
        psAssignment.length === 1
    ) {
        var isContinue = confirm("Are you sure you want to submit ? Click OK to continue or Cancel to remain on the screen.");

        if (isContinue) {
            var PimstoUpdate = new sforce.SObject("Pims__c");

            PimstoUpdate.Id = "{!Pims__c.Id}";
            PimstoUpdate.Status__c = "Under Review";

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

            if (result[0].success === "true") {
                location.reload();
            } else {
                alert(
                    "An Error has Occurred. Error: \r\n" +
                    result[0].errors.message
                );
            }
        }
    } else {
        alert(
            "Nopes"
        );
    }
} catch (e) {
    alert(
        "An unexpected Error has Occurred. Error: \r\n" +
        e
    );
}

 
Swayam  AroraSwayam Arora
Try calling apex method from the button. Apex class should not have With Sharing keyword. Code will run in System mode.


Please close the thread marking this answer as Best Answer if it really helped. Closing the thread help others finding the correct answer.