The User Password Setup dialog allows users to apply a new password, or change a password for access to a given record. This dialog appears when the user clicks the password padlock button. The following illustration shows the User Password Setup dialog.
Password control requires that you store the password entered in this dialog with the record, and allow access to the record only if the user enters its corresponding password.
Once the user saves the record and attempts to access the record again, another dialog appears (invoked from the getstring() function), asking the user to enter the password assigned previously.
Complete the following steps to add password protection for records in a given window. Once you’ve enabled password protection, you can use the User Password Setup dialog to change an existing password for a record, or assign a new password to a previously non-passworded record:
Create a password field, and add it to the table whose records you want accessed through password control. Use the Microsoft Dynamics GP Password data type as the basis for this field. This is a string data type with a keyable length of 10, and which forces uppercase characters.
Open the layout for the window, then drag the global field named ‘Password Button’ to the window area. Position this field next to the right edge of the window’s key field.
Global field |
Control |
---|---|
Password Button |
|
Add the new password field created in step 1 to the window, and position it outside the window area. This allows you to save the password with the record. With the password field selected, set the following properties:
Visible |
False |
Editable |
False |
Attach a change script to the Password Button field similar to the following example. This script will open the User Password Setup window and return the new or changed password to the invisible password field (IG_Lead_Password, in the following example). This is the password that’s stored with the lead record.
if empty('Lead ID') then focus field 'Lead ID'; warning "You must enter a lead ID before assigning a password."; abort script; end if; open form SY_Set_Change_Password return to 'Lead Password'; {Set a flag that indicates whether the password is being changed.} '(L) Changed' of window Set_Change_Password of form SY_Set_Change_Password = false; {---------------------------------------------------------------- If there is an existing password for the lead record, set a field to that password, allowing the user to enter the old password in the User Password Setup window prior to entering a different one. ----------------------------------------------------------------} 'Dummy Password' of window Set_Change_Password of form SY_Set_Change_Password = 'Lead Password' of table IG_Leads_MSTR;
Use a change script in the window’s key field similar to the following example. Upon the successful retrieval of a record, this script ascertains whether a password exists for the current record. If there is one, the getstring() function prompts the user for a password.
The script then compares the entry from the getstring() dialog to the string stored with the record. If they don’t match, a dialog prompts the user to retry until they enter the correct password or click Cancel.
local string l_Password; local boolean l_Correct_Password; 'Lead ID' of table IG_Leads_MSTR = 'Lead ID' of window 'Lead Maintenance'; release table IG_Leads_MSTR; change table IG_Leads_MSTR by IG_Leads_MSTR_Key1; if err() = OKAY then {Check to see if a password was applied to this lead record.} if not empty('Lead Password' of table IG_Leads_MSTR) then {A password was applied to this lead record.} if not getstring("Enter a password for this Lead ID", true, l_Password) then {The user clicked Cancel in the dialog box, so release the table and abort the script.} release table IG_Leads_MSTR; clear field 'Lead ID'; focus field 'Lead ID'; abort script; else if upper(l_Password) <> upper('Lead Password' of table IG_Leads_MSTR) then clear field l_Password; while not l_Correct_Password do if not getstring("You've entered the wrong password, please reenter.", true, l_Password) then {The user clicked Cancel.} release table IG_Leads_MSTR; abort script; else {User clicked OK.} if upper(l_Password) = upper('Lead Password' of table IG_Leads_MSTR) then l_Correct_Password = true; end if; end if; end while; end if; end if; end if; {Retrieve the record.} copy from table IG_Leads_MSTR to window 'Lead Maintenance'; clear changes form IG_Lead_Maintenance; enable 'Delete Button'; lock 'Lead ID'; {Set the note index.} if empty('Note Index' of table IG_Leads_MSTR) then call Get_Next_Note_Index, 'Note Index' of table IG_Leads_MSTR; save table IG_Leads_MSTR; change table IG_Leads_MSTR; end if; else {No record exists. Allow the user to create a new one.} enable 'Delete Button'; lock 'Lead ID'; run script 'Dummy Record Note Show Hide'; call Get_Next_Note_Index, 'Note Index'; end if;