You need to sign in to do that
Don't have an account?

How to override edit conditionally?
I have a custom Invoice object which gets a related Case created if the invoice goes overdue. That works fine. Now, we want to stop the invoice from being edited by anyone except users from a particular profile, once the invoice has a related Case. If I use the standard button override, I end up with a recursive loop because I'm trying to use the standard edit functionality (when they are allowed to edit), so it keeps calling my scontrol. Current (bad) code is as follows:
Using retURL + "/e" simply causes the function to be called again and again forever if the conditions are met, so it is obviously not the way to do it.
Basically I want to avoid rewriting all the edit functionality but stop certain users from editing the record under certain conditions (i.e. once a case has been created and if the user is not from a named profile).
Does anyone have any ideas to help me here?
Thanks,
Erica
Code:
function EditInvoice() { var IsCase ="{!m62_Invoice__c.Case_Number__c}"; var TopDog = false; var _profile = "{!$Profile.Name}"; if ((_profile == "Financial Controller") || (_profile == "System Administrator")){ TopDog = true; } alert("Profile is " + _profile + " topdog is " + TopDog); var retURL= escape("/{!m62_Invoice__c.Id}"); if ((IsCase == "") || TopDog) { // No Case been created OR profile is that of financial controller or Sysadmin parent.location.href = retURL+"/e"; } else { alert ("You cannot edit the invoice once a Case has been added"); parent.location.href = retURL; } }
Using retURL + "/e" simply causes the function to be called again and again forever if the conditions are met, so it is obviously not the way to do it.
Basically I want to avoid rewriting all the edit functionality but stop certain users from editing the record under certain conditions (i.e. once a case has been created and if the user is not from a named profile).
Does anyone have any ideas to help me here?
Thanks,
Erica
Message Edited by HL-Dev on 01-23-2008 08:29 AM
All Answers
Message Edited by HL-Dev on 01-23-2008 08:29 AM
Doesn't the parameter "true" at the end of the URLFOR function indicate that 'nooverride=1'? When I look at the help on URLFOR, it says to set the last parameter to true to set 'no override'. If not, how do I add the 'nooverride=1' to the statement?
How do you know what inputs the URLFOR function needs? I'm working in the dark here, as the docs don't explain this in any way that I understand, unless I'm looking in the wrong place (SF Help).
Also, Greg, when you suggest putting the parent.location.href into a variable, isn't that what I'm doing with retURLView?
Obviously I'm missing something! I really appreciate the help.
Erica
Message Edited by m62Dev on 01-25-2008 03:02 AM
I'd still appreciate some pointers regarding where I can find info on the inputs to the URLFOR, i.e. how do you know what they need to be?
Thanks, guys.
Erica