Skip to content

Instantly share code, notes, and snippets.

@jkuester
Last active November 12, 2021 17:16
Show Gist options
  • Save jkuester/292b0a584f7fc77a7d6c768f3c7c1ba3 to your computer and use it in GitHub Desktop.
Save jkuester/292b0a584f7fc77a7d6c768f3c7c1ba3 to your computer and use it in GitHub Desktop.
Script for finding note fields that have been improperly set to required. Execute the script from the root directory of your config.
#!/usr/bin/env bash
set -Eeuo pipefail
msg() {
echo >&2 -e "${1-}"
}
is_readonly='[^>]*readonly="true\(\)"'
is_string='[^>]*type="string"'
is_required='[^>]*required="true\(\)"'
is_calculate='[^>]*calculate=".+?"'
msg "Searching [${PWD}] for forms with required notes..."
msg
required_notes_count=0
while read file_path;
do
if [ -n "$file_path" ]
then
# Get the nodeset values from any string elements that are readonly and required, but do not have a calculate
required_notes=$(grep -oP "<[^>]*nodeset=\"\K(.*?)(?=\"(?=${is_readonly})(?=${is_required})(?=${is_string})(?!${is_calculate})(.*?)\/>)" "${file_path}") || true
if [ -n "$required_notes" ]
then
msg "Required note(s) found in [${file_path}]"
msg "${required_notes}"
msg
required_notes_count=$((required_notes_count+1))
fi
fi
done <<< "$(find "${PWD}" -name '*.xml')"
if [ $required_notes_count == 0 ]
then
msg "SUCCESS: No required notes found!"
else
msg "WARNING: required notes found in ${required_notes_count} form(s). See the details above."
fi
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:h="http://www.w3.org/1999/xhtml">
<!-- Do not copy the required attribute for notes -->
<xsl:template match="/h:html/h:head/xf:model/xf:bind[@type='string' and @readonly='true()' and @required='true()' and not(@calculate)]/@required">
</xsl:template>
<!-- Copy everything else -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment