The customer app from the series Building a customer app in Uniface 10 got an administration area in its last stage. Nine new forms were generated, and one existing form needed a change: the "More functions" menu should get a button "Administration...". That button should be dimmed for users who are not administrators.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).
New forms in this project are generated as XML and imported. For an existing form the same route works, but the starting point has to be the form as it is in the repository, not a generated copy.
Step 1: export the form
In the IDE, the main menu (≡) has an entry Export. The dialog has a field Object Name next to Component and a File Name at the bottom. With the component name and a target file, Export wrote the form with its entity and all field occurrences. The message line said: "Total number of occurrences exported: 19" - the form, its dummy entity and 17 fields.
This export is also the backup of the form before the change.
Step 2: patch the XML
Four things change in the export:
- the script: one label line, one check in
exec, one new entry, - the form picture: one more field token in the row of the last button,
- a new field occurrence for the button,
- nothing else - no other field, no entity property.
The script reads the export, applies the changes and writes the import file. Every replacement must match exactly once, otherwise the script stops:
def rep(a, b):
global t
assert t.count(a) == 1, a
t = t.replace(a, b)
rep('\tBTN_DQ.MORE_DMY = "Data quality & exports..."\n', '\tBTN_DQ.MORE_DMY = "Data quality & exports..."\n\tBTN_ADMIN.MORE_DMY = "Administration..."\n')
rep(''' activate "USER_SVC".CURRENT_USER(vUser, vRole)
INFO.MORE_DMY = "Logged in as %%(vUser) (%%(vRole))"
edit
''', ''' activate "USER_SVC".CURRENT_USER(vUser, vRole)
INFO.MORE_DMY = "Logged in as %%(vUser) (%%(vRole))"
if (vRole != "ADMIN")
$fieldsyntax(BTN_ADMIN.MORE_DMY) = "DIM"
endif
edit
''')
rep(''' activate "DQ_FRM".exec()
return 0
end
''', ''' activate "DQ_FRM".exec()
return 0
end
entry DO_ADMIN
call SESSION_OK
if ($status < 0)
return -1
endif
activate "ADMIN_MNU".exec()
return 0
end
''')
rep(' &uFRM;TYP=F&uSEP;NAM=BTN_DQ&uSEP;WID=30&uSEP;HEI=1&uFRM;\n', ' &uFRM;TYP=F&uSEP;NAM=BTN_DQ&uSEP;WID=30&uSEP;HEI=1&uFRM; &uFRM;TYP=F&uSEP;NAM=BTN_ADMIN&uSEP;WID=30&uSEP;HEI=1&uFRM;\n')
occs = re.findall(r'<OCC>\n(.*?)</OCC>\n', t, re.S)
src = [o for o in occs if '<DAT name="ULABEL">BTN_DQ</DAT>' in o]
assert len(src) == 1
o = src[0]
n = o.replace('<DAT name="ULABEL">BTN_DQ</DAT>', '<DAT name="ULABEL">BTN_ADMIN</DAT>').replace('\tcall DO_DQ\n', '\tcall DO_ADMIN\n')
assert n.count('BTN_ADMIN') == 1 and 'DO_ADMIN' in n
rep('<OCC>\n' + o + '</OCC>\n', '<OCC>\n' + o + '</OCC>\n<OCC>\n' + n + '</OCC>\n')
The new field is a copy of the button next to it, with a new name and a new trigger. That keeps all widget properties (type, interface, description) the same as in the buttons that are already there. The script text in the XML is escaped, so the new entry uses < where the ProcScript has <.
Step 3: import, compile, compare
The import (≡ - Import XML...) reported "Successfully imported 20 records" - one more than the export. The form was open in an editor tab, so it had to be reloaded from the repository before compiling. The compiler reported 0 errors and the one warning that every form with a dummy entity gets (1016, entity not found in the application model).
After the import the repository was read again and compared with the intended result: the script of the form equals the script in the import file, and the form picture of the repository is contained in it unchanged. These are the two pieces of ProcScript in the repository after the import:
operation exec
variables
string vUser, vRole
endvariables
call SET_LABELS
activate "USER_SVC".CURRENT_USER(vUser, vRole)
INFO.MORE_DMY = "Logged in as %%(vUser) (%%(vRole))"
if (vRole != "ADMIN")
$fieldsyntax(BTN_ADMIN.MORE_DMY) = "DIM"
endif
edit
end
entry DO_ADMIN
call SESSION_OK
if ($status < 0)
return -1
endif
activate "ADMIN_MNU".exec()
return 0
end
The click test
- As administrator, the button opened the administration menu.
- As a user with role READ and as a user with role EDIT, the button was dimmed, and a click on it did nothing.
- The administration menu checks the role again when it opens, so a call from somewhere else would not bypass the check.
Notes
- Export first, patch the export, import - in that order. The export is the only reliable source for an existing form.
- Copy an existing field occurrence instead of writing one from scratch.
- Let the patch script fail when a search text is not found exactly once.
- Compare the repository with the import file afterwards, not only the compiler output.
The same route added a status line to the main menu of the app; there the entity also had to grow by two rows, which is one more replacement in the form picture.
Top comments (0)